/**
 * smoke-http/types.ts — CLI args + probe + report shape for the HTTP smoke prober.
 */
import { z } from 'zod';

export const ProbeSchema = z.object({
  url: z.string().url(),
  expect: z.number().int().min(100).max(599).default(200),
  method: z.enum(['GET', 'HEAD']).default('GET'),
  label: z.string().optional(),
});

export type Probe = z.infer<typeof ProbeSchema>;

export const SmokeHttpArgsSchema = z.object({
  probes: z.array(ProbeSchema).min(1),
  timeoutMs: z.number().int().min(100).max(60_000).default(5000),
  retries: z.number().int().min(1).max(50).default(10),
  retryDelayMs: z.number().int().min(50).max(10_000).default(500),
  followRedirects: z.boolean().default(true),
  concurrency: z.number().int().min(1).max(32).default(4),
});

export type SmokeHttpArgs = z.infer<typeof SmokeHttpArgsSchema>;

// ─── Report ───────────────────────────────────────────────────────────────

export type ProbeStatus = 'pass' | 'fail';

export interface ProbeResult {
  url: string;
  label: string | null;
  method: 'GET' | 'HEAD';
  expect: number;
  actual: number | null;
  attempts: number;
  durationMs: number;
  status: ProbeStatus;
  error?: string;
  redirectChain?: string[];
}

export interface SmokeHttpReport {
  results: ProbeResult[];
}

// ─── Output envelope ──────────────────────────────────────────────────────

export interface SmokeHttpOutput {
  success: boolean;
  command: 'smoke-http';
  data: {
    totalProbes: number;
    passed: number;
    failed: number;
    allPassed: boolean;
  };
  report: SmokeHttpReport | null;
  errors: string[];
  warnings: string[];
  nextSteps: string[];
}
