import { areaExists, type NurseServiceArea } from './types';

const area = (id: number, cityId: number, districtId: number | null): NurseServiceArea => ({
  id,
  cityId,
  cityNameFa: '',
  cityNameEn: '',
  districtId,
  districtNameFa: null,
  districtNameEn: null,
  isWholeCity: districtId == null,
  isActive: true,
});

describe('areaExists — coverage-area duplicate guard', () => {
  const areas = [area(1, 101, null), area(2, 101, 1001)];

  it('detects a duplicate whole-city area (null district treated as a real value)', () => {
    expect(areaExists(areas, 101, null)).toBe(true);
  });

  it('detects a duplicate city+district area', () => {
    expect(areaExists(areas, 101, 1001)).toBe(true);
  });

  it('treats whole-city and a specific district in the same city as distinct', () => {
    expect(areaExists([area(1, 101, null)], 101, 1002)).toBe(false);
  });

  it('is false for a city not yet covered', () => {
    expect(areaExists(areas, 201, null)).toBe(false);
  });
});
