/**
 * status CLI types — Input spec and output result
 */

import { z } from 'zod';

export const StatusSpecSchema = z.object({
  verbose: z.boolean().optional().default(false),
});

export type StatusSpec = z.infer<typeof StatusSpecSchema>;

export const BranchInfoSchema = z.object({
  name: z.string(),
  type: z.enum(['feature', 'release', 'hotfix', 'main', 'develop', 'other']),
  ahead: z.number(),
  behind: z.number(),
  tracking: z.string().optional(),
  lastCommit: z.string().optional(),
  lastAuthor: z.string().optional(),
});

export type BranchInfo = z.infer<typeof BranchInfoSchema>;

export const WorktreeInfoSchema = z.object({
  path: z.string(),
  branch: z.string(),
  isBare: z.boolean(),
  isPrunable: z.boolean(),
});

export type WorktreeInfo = z.infer<typeof WorktreeInfoSchema>;

export const ComparisonSchema = z.object({
  branches: z.array(z.string()),
  fromBranch: z.string(),
  toBranch: z.string(),
  aheadCount: z.number(),
  behindCount: z.number(),
});

export type Comparison = z.infer<typeof ComparisonSchema>;

export const WorkingTreeStatusSchema = z.object({
  isDirty: z.boolean(),
  isRebasing: z.boolean(),
  isMerging: z.boolean(),
  isCherryPicking: z.boolean(),
  unstagedCount: z.number(),
  stagedCount: z.number(),
});

export type WorkingTreeStatus = z.infer<typeof WorkingTreeStatusSchema>;

export const ActionSchema = z.object({
  priority: z.enum(['critical', 'high', 'medium', 'low']),
  action: z.string(),
  reason: z.string(),
});

export type Action = z.infer<typeof ActionSchema>;

export const StatusResultSchema = z.object({
  success: z.boolean(),
  currentBranch: z.string(),
  branches: z.array(BranchInfoSchema),
  tags: z.array(z.string()),
  comparisons: z.array(ComparisonSchema).optional(),
  workingTree: WorkingTreeStatusSchema,
  worktrees: z.array(WorktreeInfoSchema).optional(),
  actions: z.array(ActionSchema).optional(),
  error: z.string().optional(),
});

export type StatusResult = z.infer<typeof StatusResultSchema>;
