import { describe, it, expect } from "vitest";
import { readFileSync } from "node:fs";
import { resolve } from "node:path";

describe("Cart Store", () => {
  const storePath = resolve(__dirname, "../../stores/cart.ts");
  const content = readFileSync(storePath, "utf-8");

  it("should define useCartStore with defineStore", () => {
    expect(content).toContain("defineStore");
    expect(content).toContain("useCartStore");
  });

  it("should have CartItem interface with required fields", () => {
    expect(content).toContain("equipment_id");
    expect(content).toContain("name");
    expect(content).toContain("quantity");
    expect(content).toContain("rental_price");
    expect(content).toContain("image_url");
  });

  it("should have totalCount getter", () => {
    expect(content).toContain("totalCount");
    expect(content).toContain("reduce");
  });

  it("should have isEmpty getter", () => {
    expect(content).toContain("isEmpty");
  });

  it("should have hasItems getter", () => {
    expect(content).toContain("hasItems");
  });

  it("should have apiItems getter for rental request payload", () => {
    expect(content).toContain("apiItems");
    expect(content).toContain("equipment_id");
    expect(content).toContain("quantity");
  });

  it("should have addItem action", () => {
    expect(content).toContain("addItem");
    expect(content).toContain("existing");
    expect(content).toContain("quantity += 1");
  });

  it("should have addItemByFields action", () => {
    expect(content).toContain("addItemByFields");
  });

  it("should have removeItem action", () => {
    expect(content).toContain("removeItem");
    expect(content).toContain("splice");
  });

  it("should have updateQuantity action", () => {
    expect(content).toContain("updateQuantity");
    expect(content).toContain("quantity <= 0");
  });

  it("should have incrementQuantity action", () => {
    expect(content).toContain("incrementQuantity");
  });

  it("should have decrementQuantity action", () => {
    expect(content).toContain("decrementQuantity");
  });

  it("should have clearCart action", () => {
    expect(content).toContain("clearCart");
    expect(content).toContain("items = []");
  });

  it("should have RentalRequestPayload interface", () => {
    expect(content).toContain("RentalRequestPayload");
    expect(content).toContain("event_name");
    expect(content).toContain("date_start");
    expect(content).toContain("date_end");
    expect(content).toContain("location");
    expect(content).toContain("person_count");
    expect(content).toContain("contact_name");
    expect(content).toContain("contact_email");
    expect(content).toContain("contact_phone");
    expect(content).toContain("contact_street");
    expect(content).toContain("contact_postalcode");
    expect(content).toContain("contact_city");
    expect(content).toContain("message");
    expect(content).toContain("items");
  });

  it("should have RentalRequestResponse interface", () => {
    expect(content).toContain("RentalRequestResponse");
    expect(content).toContain("reference_number");
    expect(content).toContain("status");
  });

  it("should use TypeScript", () => {
    expect(content).toContain("import type");
    expect(content).toContain("export interface");
  });
});
