import { describe, it, expect } from "vitest";
import {
  equipmentBaseSchema,
  equipmentStatusSchema,
} from "../equipment";

const CAT = "11111111-1111-1111-1111-111111111111";
const VEH = "22222222-2222-2222-2222-222222222222";

describe("equipmentBaseSchema", () => {
  it("verlangt Name und Kategorie", () => {
    expect(equipmentBaseSchema.safeParse({ name: "", categoryId: CAT }).success).toBe(false);
    expect(equipmentBaseSchema.safeParse({ name: "Pumpe", categoryId: "x" }).success).toBe(false);
  });

  it("erlaubt leere vehicleId (im Gerätehaus) -> undefined", () => {
    const r = equipmentBaseSchema.safeParse({ name: "Pumpe", categoryId: CAT, vehicleId: "" });
    expect(r.success).toBe(true);
    if (r.success) expect(r.data.vehicleId).toBeUndefined();
  });

  it("akzeptiert eine gültige vehicleId (Zuordnung)", () => {
    const r = equipmentBaseSchema.safeParse({ name: "Pumpe", categoryId: CAT, vehicleId: VEH });
    expect(r.success).toBe(true);
    if (r.success) expect(r.data.vehicleId).toBe(VEH);
  });
});

describe("equipmentStatusSchema", () => {
  it("akzeptiert nur asset_status-Werte", () => {
    expect(equipmentStatusSchema.safeParse({ id: CAT, status: "ausser_dienst" }).success).toBe(true);
    expect(equipmentStatusSchema.safeParse({ id: CAT, status: "weg" }).success).toBe(false);
  });
});
