import 'reflect-metadata';
import { CreateInquiryDto } from '../dto/create-inquiry.dto';
import { ListInquiriesDto } from '../dto/list-inquiries.dto';

describe('CreateInquiryDto', () => {
  describe('validation metadata', () => {
    it('has validation metadata on listingId property', () => {
      const metadata = Reflect.getMetadata(
        'swagger/apiModelProperties',
        CreateInquiryDto.prototype,
        'listingId',
      );
      expect(metadata).toBeDefined();
      expect(metadata.description).toBe('ID of the listing');
    });

    it('has validation metadata on message property', () => {
      const metadata = Reflect.getMetadata(
        'swagger/apiModelProperties',
        CreateInquiryDto.prototype,
        'message',
      );
      expect(metadata).toBeDefined();
      expect(metadata.description).toBe('Tin nhắn yêu cầu tư vấn');
    });

    it('has optional phone property metadata', () => {
      const metadata = Reflect.getMetadata(
        'swagger/apiModelProperties',
        CreateInquiryDto.prototype,
        'phone',
      );
      expect(metadata).toBeDefined();
      expect(metadata.description).toBe('Số điện thoại liên hệ');
    });
  });

  describe('property assignment', () => {
    it('can assign all required properties', () => {
      const dto = new CreateInquiryDto();
      dto.listingId = 'listing-1';
      dto.message = 'Tôi muốn xem nhà';

      expect(dto.listingId).toBe('listing-1');
      expect(dto.message).toBe('Tôi muốn xem nhà');
    });

    it('can assign optional phone', () => {
      const dto = new CreateInquiryDto();
      dto.phone = '0901234567';

      expect(dto.phone).toBe('0901234567');
    });

    it('phone defaults to undefined when not assigned', () => {
      const dto = new CreateInquiryDto();

      expect(dto.phone).toBeUndefined();
    });
  });
});

describe('ListInquiriesDto', () => {
  describe('validation metadata', () => {
    it('has page property metadata', () => {
      const metadata = Reflect.getMetadata(
        'swagger/apiModelProperties',
        ListInquiriesDto.prototype,
        'page',
      );
      expect(metadata).toBeDefined();
      expect(metadata.default).toBe(1);
    });

    it('has limit property metadata', () => {
      const metadata = Reflect.getMetadata(
        'swagger/apiModelProperties',
        ListInquiriesDto.prototype,
        'limit',
      );
      expect(metadata).toBeDefined();
      expect(metadata.default).toBe(20);
    });
  });

  describe('property assignment', () => {
    it('can assign page and limit', () => {
      const dto = new ListInquiriesDto();
      dto.page = 2;
      dto.limit = 50;

      expect(dto.page).toBe(2);
      expect(dto.limit).toBe(50);
    });

    it('page and limit default to undefined when not assigned', () => {
      const dto = new ListInquiriesDto();

      expect(dto.page).toBeUndefined();
      expect(dto.limit).toBeUndefined();
    });
  });
});
