import { z } from 'zod';
import type { PolicyVerdict } from '../lib/migration-policy.js';

export const CreateSpecSchema = z.object({
  cwd: z.string().min(1),
  contextName: z.string().min(1),
  description: z.string().min(1),
  /** Optional: target a single migration assembly (required for multi-provider contexts unless allProviders=true). */
  assembly: z.string().optional(),
  /** For multi-provider contexts (Studio), create the migration in EVERY assembly. Default: true. */
  allProviders: z.boolean().optional().default(true),
  /** Optional override of the startup project used by `dotnet ef`. */
  startupProject: z.string().optional(),
  /** Confirmation token required to create on a 🟡 branch (release/hotfix). */
  confirm: z.boolean().optional().default(false),
  /** Dry-run: compute name + paths, do NOT spawn dotnet. */
  dryRun: z.boolean().optional().default(false),
});
export type CreateSpec = z.infer<typeof CreateSpecSchema>;

export interface CreateAssemblyResult {
  assemblyName: string;
  migrationName: string;
  csprojPath: string;
  output: string;
  success: boolean;
  error?: string;
  filesCreated: string[];
  /** SQL objects (schema.name) frozen into this migration from the SqlObjects folder. */
  sqlObjectsInlined: string[];
  /** The generated Up() drops/destroys data — review before applying or committing. */
  destructive?: boolean;
}

export interface CreateResult {
  success: boolean;
  cwd: string;
  contextName: string;
  assemblies: CreateAssemblyResult[];
  warnings: string[];
  error?: string;
  /** 3-tier verdict for the create operation on this branch. */
  policy?: PolicyVerdict;
  /** Set on a 🔴 verdict (protected branch) — nothing was created. */
  blocked?: boolean;
  /** Set on a 🟡 verdict (release/hotfix) reached without `confirm:true` — nothing was created. */
  needsConfirmation?: boolean;
}
