/**
 * project-inventory/types.ts — CLI args + report shape.
 *
 * Source of truth for the JSON envelope consumed by `ba-develop`
 * handlers to feed the E-P-C-T workflow's exploration step.
 */
import { z } from 'zod';

export const InventoryDomains = ['domain', 'data', 'api', 'frontend'] as const;
export type InventoryDomain = (typeof InventoryDomains)[number];

export const ProjectInventoryArgsSchema = z.object({
  /** Absolute path to the generated SmartStack project root. */
  projectPath: z.string().min(1),
  /** Optional dump path; stdout is always populated. */
  outputFile: z.string().optional(),
  /** Subset of scan domains. Empty / all = every domain. */
  domains: z.array(z.enum(InventoryDomains)).default([]),
});

export type ProjectInventoryArgs = z.infer<typeof ProjectInventoryArgsSchema>;

// ─── Report shape ─────────────────────────────────────────────────────────

export interface DomainEntity {
  name: string;
  file: string;
  baseClass: string | null;
  namespace: string | null;
}

export interface MigrationInfo {
  file: string;
  name: string;
  timestamp: string | null;
  tablesCreated: string[];
  tablesDropped: string[];
  action: 'create' | 'alter' | 'drop' | 'unknown';
}

export interface SeedProviderInfo {
  file: string;
  className: string;
  entitiesReferenced: string[];
  tablesReferenced: string[];
  seedsNavigation: boolean;
  seedsPermissions: boolean;
}

export interface ControllerInfo {
  file: string;
  className: string;
  route: string | null;
  httpActions: string[];
}

export interface PageInfo {
  file: string;
  entity: string;
  kind: 'list' | 'detail' | 'form' | 'dashboard' | 'create' | 'edit' | 'other';
}

export interface InventoryReport {
  projectPath: string;
  hasDotnet: boolean;
  hasFrontend: boolean;
  domain: { entities: DomainEntity[] };
  data: { migrations: MigrationInfo[]; seedProviders: SeedProviderInfo[] };
  api: { controllers: ControllerInfo[] };
  frontend: {
    pages: PageInfo[];
    registries: string[];
    i18n: { locales: string[]; namespaces: string[] };
  };
}

export interface ProjectInventoryOutput {
  success: boolean;
  command: 'project-inventory';
  data: {
    scannedAt: string;
    durationMs: number;
    domainsRun: InventoryDomain[];
  };
  report: InventoryReport | null;
  errors: string[];
  warnings: string[];
  nextSteps: string[];
}
