import { describe, it, expect } from "vitest";
import { brigadeUserCreateSchema, brigadeUserDeactivateSchema } from "../brigade-user";

describe("brigadeUserCreateSchema", () => {
  const valid = {
    email: "Neu@FF.at",
    name: "Neue Person",
    rolle: "wehr_read",
  };

  it("akzeptiert wehr_admin und wehr_read und normalisiert die E-Mail", () => {
    const r = brigadeUserCreateSchema.safeParse(valid);
    expect(r.success).toBe(true);
    if (r.success) expect(r.data.email).toBe("neu@ff.at");
    expect(brigadeUserCreateSchema.safeParse({ ...valid, rolle: "wehr_admin" }).success).toBe(true);
  });

  it("lehnt platform_admin ab (nicht zuweisbar durch Wehr-Admin)", () => {
    expect(
      brigadeUserCreateSchema.safeParse({ ...valid, rolle: "platform_admin" }).success,
    ).toBe(false);
  });

  it("verlangt Name und gültige E-Mail", () => {
    expect(brigadeUserCreateSchema.safeParse({ ...valid, name: "" }).success).toBe(false);
    expect(brigadeUserCreateSchema.safeParse({ ...valid, email: "keine-mail" }).success).toBe(false);
  });
});

describe("brigadeUserDeactivateSchema", () => {
  it("verlangt eine gültige UUID", () => {
    expect(
      brigadeUserDeactivateSchema.safeParse({ userId: "11111111-1111-1111-1111-111111111111" }).success,
    ).toBe(true);
    expect(brigadeUserDeactivateSchema.safeParse({ userId: "x" }).success).toBe(false);
  });
});
