import { z } from 'zod';
import type { SquashBranchType } from '../lib/squash-base.js';

export const StatusSpecSchema = z.object({
  cwd: z.string().min(1),
  baseBranch: z.string().optional(),
});
export type StatusSpec = z.infer<typeof StatusSpecSchema>;

export interface AssemblyStatus {
  assemblyName: string;
  contextName: string;
  migrationsDir: string;
  provider: string | null;
  version: string;
  total: number;
  applied: number;
  pending: number;
  branchOnly: string[];
  /** 🔒 Names of the migrations inherited from the reference branch (preserved on squash; never deletable except via -BruteForce). */
  parentMigrations: string[];
  /** ☠️ Reference-branch migrations MISSING from the working tree (deleted/renamed locally). Non-empty ⇒ a merge would drop them from production. */
  missingFromWorkingTree: string[];
  snapshotDirty: boolean;
  error?: string;
}

export interface StatusResult {
  success: boolean;
  cwd: string;
  kind: 'generated' | 'studio' | 'unknown';
  currentBranch: string;
  baseBranch: string;
  /** Branch type that selected the reference branch (see lib/squash-base.ts). */
  branchType?: SquashBranchType;
  /** Whether `baseBranch` actually resolved to a real ref. When false, `branchOnly` is not computed. */
  baseResolved: boolean;
  /** Commits the current branch is behind the reference branch (0 = in sync / not computed). */
  behindBase: number;
  assemblies: AssemblyStatus[];
  warnings: string[];
  error?: string;
}
