import { describe, it, expect } from 'vitest';
import { SearchFilter } from '../value-objects/search-filter.vo';

describe('SearchFilter', () => {
  it('creates filter with all properties', () => {
    const filter = SearchFilter.create({
      query: 'căn hộ quận 7',
      propertyType: 'APARTMENT',
      transactionType: 'SALE',
      priceMin: 2_000_000_000,
      priceMax: 8_000_000_000,
      areaMin: 60,
      areaMax: 150,
      bedrooms: 2,
      district: 'Quận 7',
      city: 'Hồ Chí Minh',
      sortBy: 'price_desc',
      page: 4,
      perPage: 30,
    });

    expect(filter.query).toBe('căn hộ quận 7');
    expect(filter.propertyType).toBe('APARTMENT');
    expect(filter.transactionType).toBe('SALE');
    expect(filter.priceMin).toBe(2_000_000_000);
    expect(filter.priceMax).toBe(8_000_000_000);
    expect(filter.areaMin).toBe(60);
    expect(filter.areaMax).toBe(150);
    expect(filter.bedrooms).toBe(2);
    expect(filter.district).toBe('Quận 7');
    expect(filter.city).toBe('Hồ Chí Minh');
    expect(filter.sortBy).toBe('price_desc');
    expect(filter.page).toBe(4);
    expect(filter.perPage).toBe(30);
  });

  it('applies default sortBy as relevance', () => {
    const filter = SearchFilter.create({});
    expect(filter.sortBy).toBe('relevance');
  });

  it('applies default page as 1', () => {
    const filter = SearchFilter.create({});
    expect(filter.page).toBe(1);
  });

  it('applies default perPage as 20', () => {
    const filter = SearchFilter.create({});
    expect(filter.perPage).toBe(20);
  });

  it('caps perPage at 100', () => {
    const filter = SearchFilter.create({ perPage: 250 });
    expect(filter.perPage).toBe(100);
  });

  it('returns undefined for unset optional properties', () => {
    const filter = SearchFilter.create({});
    expect(filter.query).toBeUndefined();
    expect(filter.propertyType).toBeUndefined();
    expect(filter.transactionType).toBeUndefined();
    expect(filter.priceMin).toBeUndefined();
    expect(filter.priceMax).toBeUndefined();
    expect(filter.areaMin).toBeUndefined();
    expect(filter.areaMax).toBeUndefined();
    expect(filter.bedrooms).toBeUndefined();
    expect(filter.district).toBeUndefined();
    expect(filter.city).toBeUndefined();
  });

  it('handles empty query string', () => {
    const filter = SearchFilter.create({ query: '' });
    expect(filter.query).toBe('');
  });
});
