import { validate } from 'class-validator';
import { SubmitKycDto } from '../../presentation/dto/submit-kyc.dto';

describe('SubmitKycDto', () => {
  const validDto = (): SubmitKycDto => {
    const dto = new SubmitKycDto();
    dto.documentType = 'CCCD';
    dto.documentNumber = '001234567890';
    dto.frontImageUrl = 'https://cdn.goodgo.vn/kyc/front-123.jpg';
    return dto;
  };

  it('accepts valid required fields only', async () => {
    const dto = validDto();
    const errors = await validate(dto);
    expect(errors).toHaveLength(0);
  });

  it('accepts all fields together', async () => {
    const dto = validDto();
    dto.backImageUrl = 'https://cdn.goodgo.vn/kyc/back-123.jpg';
    dto.selfieUrl = 'https://cdn.goodgo.vn/kyc/selfie-123.jpg';

    const errors = await validate(dto);
    expect(errors).toHaveLength(0);
  });

  it('rejects empty documentType', async () => {
    const dto = validDto();
    dto.documentType = '';

    const errors = await validate(dto);
    expect(errors.some(e => e.property === 'documentType')).toBe(true);
  });

  it('rejects missing documentType', async () => {
    const dto = validDto();
    (dto as any).documentType = undefined;

    const errors = await validate(dto);
    expect(errors.some(e => e.property === 'documentType')).toBe(true);
  });

  it('rejects empty documentNumber', async () => {
    const dto = validDto();
    dto.documentNumber = '';

    const errors = await validate(dto);
    expect(errors.some(e => e.property === 'documentNumber')).toBe(true);
  });

  it('rejects missing documentNumber', async () => {
    const dto = validDto();
    (dto as any).documentNumber = undefined;

    const errors = await validate(dto);
    expect(errors.some(e => e.property === 'documentNumber')).toBe(true);
  });

  it('rejects empty frontImageUrl', async () => {
    const dto = validDto();
    dto.frontImageUrl = '';

    const errors = await validate(dto);
    expect(errors.some(e => e.property === 'frontImageUrl')).toBe(true);
  });

  it('rejects invalid frontImageUrl format', async () => {
    const dto = validDto();
    dto.frontImageUrl = 'not-a-url';

    const errors = await validate(dto);
    expect(errors.some(e => e.property === 'frontImageUrl')).toBe(true);
  });

  it('rejects missing frontImageUrl', async () => {
    const dto = validDto();
    (dto as any).frontImageUrl = undefined;

    const errors = await validate(dto);
    expect(errors.some(e => e.property === 'frontImageUrl')).toBe(true);
  });

  it('rejects invalid backImageUrl format', async () => {
    const dto = validDto();
    dto.backImageUrl = 'not-a-url';

    const errors = await validate(dto);
    expect(errors.some(e => e.property === 'backImageUrl')).toBe(true);
  });

  it('rejects invalid selfieUrl format', async () => {
    const dto = validDto();
    dto.selfieUrl = 'not-a-url';

    const errors = await validate(dto);
    expect(errors.some(e => e.property === 'selfieUrl')).toBe(true);
  });

  it('rejects non-string documentType', async () => {
    const dto = validDto();
    (dto as any).documentType = 123;

    const errors = await validate(dto);
    expect(errors.some(e => e.property === 'documentType')).toBe(true);
  });
});
