/**
 * list CLI types — input spec + result.
 *
 * Read-only: scans a worktree and returns all EF Core migrations grouped by
 * DbContext and migration assembly. Used by the Studio's MigrationsTab and
 * by the list agent prompt.
 */
import { z } from 'zod';

export const ListSpecSchema = z.object({
  cwd: z.string().min(1, 'cwd is required'),
  contextName: z.string().optional(),
  assembly: z.string().optional(),
});
export type ListSpec = z.infer<typeof ListSpecSchema>;

export interface MigrationEntry {
  id: string;
  name: string;
  applied: boolean;
}

export interface AssemblyListing {
  assemblyName: string;
  csprojPath: string;
  migrationsDir: string;
  provider: string | null;
  version: string;
  migrations: MigrationEntry[];
  /** When `dotnet ef migrations list --json` fails, this carries the reason. */
  error?: string;
}

export interface ContextListing {
  contextName: string;
  assemblies: AssemblyListing[];
}

export interface ListResult {
  success: boolean;
  cwd: string;
  kind: 'generated' | 'studio' | 'unknown';
  contexts: ContextListing[];
  warnings: string[];
  error?: string;
}
