import { PRICING_TIERS, TIER_MAPPING } from "@/lib/config/pricing-tiers";
import {
  FEATURE_MATRIX,
  isFeatureAvailable,
} from "@/lib/config/pricing-features";

describe("Pricing Configuration", () => {
  describe("PRICING_TIERS", () => {
    it("should have exactly 5 tiers", () => {
      expect(PRICING_TIERS).toHaveLength(5);
    });

    it("should have tier2 marked as popular", () => {
      const tier2 = PRICING_TIERS.find((t) => t.id === "tier2");
      expect(tier2?.popular).toBe(true);
    });

    it("should have both English and Arabic names for all tiers", () => {
      PRICING_TIERS.forEach((tier) => {
        expect(tier.nameEn).toBeTruthy();
        expect(tier.nameAr).toBeTruthy();
      });
    });

    it("should have features in both languages", () => {
      PRICING_TIERS.forEach((tier) => {
        expect(tier.featuresEn.length).toBeGreaterThan(0);
        expect(tier.featuresAr.length).toBeGreaterThan(0);
        expect(tier.featuresEn.length).toBe(tier.featuresAr.length);
      });
    });

    it("should have correct tier IDs", () => {
      const expectedIds = ["tier1", "tier2", "tier3", "tier4", "tier5"];
      const actualIds = PRICING_TIERS.map((t) => t.id);
      expect(actualIds).toEqual(expectedIds);
    });

    it("should have increasing prices for higher tiers", () => {
      for (let i = 1; i < PRICING_TIERS.length; i++) {
        expect(PRICING_TIERS[i].priceGBP).toBeGreaterThanOrEqual(
          PRICING_TIERS[i - 1].priceGBP,
        );
      }
    });
  });

  describe("FEATURE_MATRIX", () => {
    it("should have features with both language variants", () => {
      FEATURE_MATRIX.forEach((feature) => {
        expect(feature.en).toBeTruthy();
        expect(feature.ar).toBeTruthy();
        expect(feature.availability.length).toBeGreaterThan(0);
      });
    });

    it("should correctly identify tier5-only features", () => {
      const tier5Only = FEATURE_MATRIX.filter(
        (f) => f.availability.length === 1 && f.availability[0] === "tier5",
      );
      expect(tier5Only.length).toBeGreaterThan(0);
    });

    it("should have cumulative feature availability", () => {
      // Features available in tier1 should be available in all tiers
      const tier1Features = FEATURE_MATRIX.filter((f) =>
        f.availability.includes("tier1"),
      );
      tier1Features.forEach((feature) => {
        expect(feature.availability).toContain("tier2");
        expect(feature.availability).toContain("tier3");
        expect(feature.availability).toContain("tier4");
        expect(feature.availability).toContain("tier5");
      });
    });
  });

  describe("isFeatureAvailable", () => {
    it("should return true for AI Agent in tier1", () => {
      expect(isFeatureAvailable("AI Agent", "tier1")).toBe(true);
    });

    it("should return false for Lead Generation in tier1", () => {
      expect(isFeatureAvailable("Lead Generation", "tier1")).toBe(false);
    });

    it("should return true for Lead Generation in tier5", () => {
      expect(isFeatureAvailable("Lead Generation", "tier5")).toBe(true);
    });

    it("should return false for non-existent feature", () => {
      expect(isFeatureAvailable("Non-existent Feature", "tier1")).toBe(false);
    });
  });

  describe("TIER_MAPPING", () => {
    it("should map all tier IDs to names", () => {
      expect(TIER_MAPPING.tier1).toBe("starter");
      expect(TIER_MAPPING.tier2).toBe("professional");
      expect(TIER_MAPPING.tier3).toBe("business");
      expect(TIER_MAPPING.tier4).toBe("enterprise");
      expect(TIER_MAPPING.tier5).toBe("ultimate");
    });
  });
});
