import { describe, it, expect } from 'vitest';
import {
  MedicineForm,
  StrengthUnit,
  MedicineCategory,
  MedicineProductSource,
  DosageUnit,
  ConcentrationUnit,
  allowedUnitsForForm,
  defaultUnitForForm,
} from './medicine.enums.js';

describe(MedicineForm.name, () => {
  it('has expected values', () => {
    expect(MedicineForm.TABLET).toBe('tablet');
    expect(MedicineForm.CAPSULE).toBe('capsule');
    expect(MedicineForm.LIQUID).toBe('liquid');
    expect(MedicineForm.INJECTION).toBe('injection');
    expect(MedicineForm.OTHER).toBe('other');
  });

  it('has exactly 5 forms', () => {
    expect(Object.values(MedicineForm)).toHaveLength(5);
  });
});

describe(StrengthUnit.name, () => {
  it('has expected values', () => {
    expect(StrengthUnit.MG).toBe('mg');
    expect(StrengthUnit.IU).toBe('IU');
    expect(StrengthUnit.PERCENT).toBe('%');
  });

  it('has exactly 7 units', () => {
    expect(Object.values(StrengthUnit)).toHaveLength(7);
  });
});

describe(MedicineCategory.name, () => {
  it('has expected values', () => {
    expect(MedicineCategory.PRESCRIPTION).toBe('prescription');
    expect(MedicineCategory.OTC).toBe('otc');
    expect(MedicineCategory.SUPPLEMENT).toBe('supplement');
  });

  it('has exactly 4 categories', () => {
    expect(Object.values(MedicineCategory)).toHaveLength(4);
  });
});

describe(MedicineProductSource.name, () => {
  it('has expected values', () => {
    expect(MedicineProductSource.MANUAL).toBe('manual');
    expect(MedicineProductSource.IMPORT).toBe('import');
  });

  it('has exactly 2 sources', () => {
    expect(Object.values(MedicineProductSource)).toHaveLength(2);
  });
});

describe(DosageUnit.name, () => {
  it('has expected values', () => {
    expect(DosageUnit.TABLET).toBe('tablet');
    expect(DosageUnit.CAPSULE).toBe('capsule');
    expect(DosageUnit.ML).toBe('ml');
    expect(DosageUnit.VIAL).toBe('vial');
    expect(DosageUnit.DOSE).toBe('dose');
  });

  it('has exactly 5 units', () => {
    expect(Object.values(DosageUnit)).toHaveLength(5);
  });
});

describe(ConcentrationUnit.name, () => {
  it('has expected values', () => {
    expect(ConcentrationUnit.MG_PER_ML).toBe('mg/mL');
    expect(ConcentrationUnit.MCG_PER_ML).toBe('mcg/mL');
    expect(ConcentrationUnit.UNITS_PER_ML).toBe('units/mL');
  });

  it('has exactly 3 units', () => {
    expect(Object.values(ConcentrationUnit)).toHaveLength(3);
  });
});

describe('allowedUnitsForForm', () => {
  it('returns tablet for tablet form', () => {
    expect(allowedUnitsForForm(MedicineForm.TABLET)).toEqual([DosageUnit.TABLET]);
  });

  it('returns capsule for capsule form', () => {
    expect(allowedUnitsForForm(MedicineForm.CAPSULE)).toEqual([DosageUnit.CAPSULE]);
  });

  it('returns ml for liquid form', () => {
    expect(allowedUnitsForForm(MedicineForm.LIQUID)).toEqual([DosageUnit.ML]);
  });

  it('returns vial and ml for injection form', () => {
    expect(allowedUnitsForForm(MedicineForm.INJECTION)).toEqual([DosageUnit.VIAL, DosageUnit.ML]);
  });

  it('returns dose for other form', () => {
    expect(allowedUnitsForForm(MedicineForm.OTHER)).toEqual([DosageUnit.DOSE]);
  });
});

describe('defaultUnitForForm', () => {
  it('returns the first allowed unit', () => {
    expect(defaultUnitForForm(MedicineForm.TABLET)).toBe(DosageUnit.TABLET);
    expect(defaultUnitForForm(MedicineForm.INJECTION)).toBe(DosageUnit.VIAL);
  });
});
