import { z } from "zod";

export const ProjectSchema = z.object({
  id: z.string().min(1),
  name: z.string().min(1),
  color: z.string().min(1),
});
export type Project = z.infer<typeof ProjectSchema>;

export const SeveritySchema = z.enum(["act", "warn", "info"]);
export type Severity = z.infer<typeof SeveritySchema>;

export const KindSchema = z.enum([
  "alert",
  "ci",
  "halt",
  "decision",
  "limit",
  "gate",
  "progress",
  "build",
]);
export type Kind = z.infer<typeof KindSchema>;

export const ActionRefSchema = z.object({
  verb: z.string().min(1),
  args: z.record(z.string()),
  label: z.string().min(1),
  recommended: z.boolean().optional(),
});
export type ActionRef = z.infer<typeof ActionRefSchema>;

export const DecisionSchema = z.object({
  question: z.string().min(1),
  options: z.array(
    z.object({
      label: z.string().min(1),
      recommended: z.boolean().optional(),
    }),
  ),
  freeText: z.boolean(),
  context: z.string(),
  waitingSince: z.string(),
});
export type Decision = z.infer<typeof DecisionSchema>;

export const ItemSchema = z.object({
  id: z.string().min(1),
  source: z.string().min(1),
  project: z.string().optional(),
  reconciliationScope: z.string().min(1).optional(),
  severity: SeveritySchema,
  kind: KindSchema,
  title: z.string().min(1),
  detail: z.string(),
  ts: z.string(),
  actions: z.array(ActionRefSchema),
  decision: DecisionSchema.optional(),
});
export type Item = z.infer<typeof ItemSchema>;

export const PanelSchema = z.object({
  id: z.string().min(1),
  ts: z.string(),
  data: z.unknown(),
});
export type Panel = z.infer<typeof PanelSchema>;

export const AdapterResultSchema = z.object({
  items: z.array(ItemSchema),
  panels: z.array(PanelSchema),
  completeScopes: z.array(z.string().min(1)).optional(),
});
export type AdapterResult = z.infer<typeof AdapterResultSchema>;
