import { plainToInstance } from 'class-transformer';
import { validate } from 'class-validator';
import { describe, it, expect } from 'vitest';
import { UpdateListingStatusDto } from '../dto/update-listing-status.dto';

describe('UpdateListingStatusDto', () => {
  it('should pass validation with valid status', async () => {
    const dto = plainToInstance(UpdateListingStatusDto, {
      status: 'ACTIVE',
    });

    const errors = await validate(dto);
    expect(errors).toHaveLength(0);
    expect(dto.status).toBe('ACTIVE');
  });

  it('should pass validation with status and moderation notes', async () => {
    const dto = plainToInstance(UpdateListingStatusDto, {
      status: 'REJECTED',
      moderationNotes: 'Đã xác minh thông tin pháp lý',
    });

    const errors = await validate(dto);
    expect(errors).toHaveLength(0);
    expect(dto.status).toBe('REJECTED');
    expect(dto.moderationNotes).toBe('Đã xác minh thông tin pháp lý');
  });

  it('should fail validation with invalid status', async () => {
    const dto = plainToInstance(UpdateListingStatusDto, {
      status: 'INVALID_STATUS',
    });

    const errors = await validate(dto);
    expect(errors.length).toBeGreaterThan(0);
    const statusError = errors.find((e) => e.property === 'status');
    expect(statusError).toBeDefined();
  });

  it('should fail validation when status is missing', async () => {
    const dto = plainToInstance(UpdateListingStatusDto, {});

    const errors = await validate(dto);
    expect(errors.length).toBeGreaterThan(0);
    const statusError = errors.find((e) => e.property === 'status');
    expect(statusError).toBeDefined();
  });

  it('should accept all valid ListingStatus enum values', async () => {
    const validStatuses = ['DRAFT', 'PENDING_REVIEW', 'ACTIVE', 'RESERVED', 'SOLD', 'RENTED', 'EXPIRED', 'REJECTED'];

    for (const status of validStatuses) {
      const dto = plainToInstance(UpdateListingStatusDto, { status });
      const errors = await validate(dto);
      expect(errors).toHaveLength(0);
    }
  });
});
