import {
  ItemConditionAnswer,
  ReturnReasonAnswer,
  YesNoAnswer,
  PackageIncompleteAnswer,
  ReturnProcessQuestionSchema,
  ProductCategory,
} from './constants';
import { ReturnProcessQuestionKey } from '../models';

describe('Constants', () => {
  describe('Return Process Answers', () => {
    it('should define ItemConditionAnswer values', () => {
      expect(ItemConditionAnswer.OVP).toBe('Originalverpackt');
      expect(ItemConditionAnswer.Damaged).toBe('Geöffnet/Defekt');
    });

    it('should define ReturnReasonAnswer values', () => {
      expect(ReturnReasonAnswer.Dislike).toBe('Gefällt nicht/Widerruf');
      expect(ReturnReasonAnswer.WrongItem).toBe('Fehllieferung');
    });

    it('should define YesNoAnswer values', () => {
      expect(YesNoAnswer.Yes).toBe('Ja');
      expect(YesNoAnswer.No).toBe('Nein');
    });

    it('should define PackageIncompleteAnswer values', () => {
      expect(PackageIncompleteAnswer.OVP).toBe('Karton / Umverpackung');
      expect(PackageIncompleteAnswer.ChargingCable).toBe('Ladekabel');
      expect(PackageIncompleteAnswer.QuickStartGuide).toBe('Quickstart-Guide');
    });
  });

  describe('ProductCategory', () => {
    it('should define all product categories', () => {
      expect(ProductCategory.BookCalendar).toBe('Buch/Kalender');
      expect(ProductCategory.TonDatentraeger).toBe('Ton-/Datenträger');
      expect(ProductCategory.SpielwarenPuzzle).toBe('Spielwaren/Puzzle');
      expect(ProductCategory.SonstigesNonbook).toBe('Sonstiges und Non-Book');
      expect(ProductCategory.ElektronischeGeraete).toBe(
        'Andere Elektronische Geräte',
      );
      expect(ProductCategory.Tolino).toBe('Tolino');
    });
  });

  describe('ReturnProcessQuestionSchema', () => {
    it('should validate ItemCondition schema', () => {
      const schema =
        ReturnProcessQuestionSchema[ReturnProcessQuestionKey.ItemCondition];

      // Valid values
      expect(schema.safeParse(ItemConditionAnswer.OVP).success).toBe(true);
      expect(schema.safeParse(ItemConditionAnswer.Damaged).success).toBe(true);

      // Invalid values
      expect(schema.safeParse('invalid').success).toBe(false);
      expect(schema.safeParse('').success).toBe(false);
      expect(schema.safeParse(null).success).toBe(false);
    });

    it('should validate ReturnReason schema', () => {
      const schema =
        ReturnProcessQuestionSchema[ReturnProcessQuestionKey.ReturnReason];

      // Valid values
      expect(schema.safeParse(ReturnReasonAnswer.Dislike).success).toBe(true);
      expect(schema.safeParse(ReturnReasonAnswer.WrongItem).success).toBe(true);

      // Invalid values
      expect(schema.safeParse('invalid').success).toBe(false);
    });

    it('should validate YesNo schemas', () => {
      const schemas = [
        ReturnProcessQuestionSchema[ReturnProcessQuestionKey.ItemDefective],
        ReturnProcessQuestionSchema[ReturnProcessQuestionKey.DisplayDamaged],
        ReturnProcessQuestionSchema[ReturnProcessQuestionKey.DevicePower],
        ReturnProcessQuestionSchema[ReturnProcessQuestionKey.PackageComplete],
        ReturnProcessQuestionSchema[ReturnProcessQuestionKey.CaseDamaged],
        ReturnProcessQuestionSchema[ReturnProcessQuestionKey.UsbPortDamaged],
      ];

      schemas.forEach((schema) => {
        // Valid values
        expect(schema.safeParse(YesNoAnswer.Yes).success).toBe(true);
        expect(schema.safeParse(YesNoAnswer.No).success).toBe(true);

        // Invalid values
        expect(schema.safeParse('maybe').success).toBe(false);
      });
    });

    it('should validate PackageIncomplete schema', () => {
      const schema =
        ReturnProcessQuestionSchema[
          ReturnProcessQuestionKey.PackageMissingItems
        ];

      // Valid values - with options
      expect(
        schema.safeParse({
          options: [PackageIncompleteAnswer.OVP],
          other: '',
        }).success,
      ).toBe(true);

      // Valid values - with multiple options
      expect(
        schema.safeParse({
          options: [
            PackageIncompleteAnswer.OVP,
            PackageIncompleteAnswer.ChargingCable,
          ],
          other: 'Some other missing part',
        }).success,
      ).toBe(true);

      // Valid values - with only other
      expect(
        schema.safeParse({
          options: [],
          other: 'Something else is missing',
        }).success,
      ).toBe(true);

      // Invalid values
      expect(schema.safeParse({}).success).toBe(false);
      expect(schema.safeParse({ options: [] }).success).toBe(false);
      expect(schema.safeParse({ options: ['invalid'] }).success).toBe(false);
    });

    it('should validate DeliveredItem schema', () => {
      const schema =
        ReturnProcessQuestionSchema[ReturnProcessQuestionKey.DeliveredItem];

      // Valid values
      expect(
        schema.safeParse({
          ean: '1234567890123',
          format: 'Book',
          formatDetail: 'Hardcover',
          name: 'Test Book',
          catalogProductNumber: '12345',
          contributors: 'John Doe',
          volume: '1',
          manufacturer: 'Test Publisher',
        }).success,
      ).toBe(true);

      // Invalid values - missing required fields
      expect(
        schema.safeParse({
          ean: '1234567890123',
          format: 'Book',
        }).success,
      ).toBe(false);

      // Invalid values - wrong types
      expect(
        schema.safeParse({
          ean: 1234567890123,
          format: 'Book',
          formatDetails: 'Hardcover',
        }).success,
      ).toBe(false);
    });
  });
});
