/**
 * Types for commit system
 * Git-like version tracking for Bangstack configurations
 */

/**
 * Operation types for diffs
 */
export type DiffOperation = 'add' | 'remove' | 'modify';

/**
 * A single change in a diff
 */
export interface DiffChange {
  op: DiffOperation;
  path: string;           // JSONPath to the changed value
  value?: any;            // New value (for add/modify)
  oldValue?: any;         // Old value (for modify/remove)
}

/**
 * A commit represents a snapshot of changes
 */
export interface Commit {
  hash: string;
  parent: string | null;  // Parent commit hash (null for initial commit)
  timestamp: string;      // ISO 8601 timestamp
  author: string;         // Author name or email
  message: string;        // Commit message
  diff: DiffChange[];     // Array of changes
  filesAffected?: string[]; // Files that would be regenerated
  referencedFiles?: string[]; // External files referenced via $ref
}

/**
 * Commit index maintains the commit chain
 */
export interface CommitIndex {
  head: string | null;    // Current HEAD commit hash
  commits: CommitMetadata[];
}

/**
 * Lightweight commit metadata for index
 */
export interface CommitMetadata {
  hash: string;
  parent: string | null;
  timestamp: string;
  author: string;
  message: string;
}

/**
 * System state tracking
 */
export interface SystemState {
  versions: {
    bangstack: string;    // Bangstack CLI version
    app: string;          // App instance version
    services?: Record<string, string>; // Service versions
  };
  commit: string | null;  // Current commit hash
  previousCommit: string | null;
  deployed?: {            // Deployment tracking
    dev?: string;
    staging?: string;
    prod?: string;
  };
}

/**
 * Bangstack directory structure
 */
export interface BangstackDirectory {
  root: string;           // .bangstack/
  config: string;         // .bangstack/config.yaml
  commits: string;        // .bangstack/commits/
  commitIndex: string;    // .bangstack/commits/index.json
  state: string;          // .bangstack/state.json
  cache: string;          // .bangstack/cache/
}

/**
 * Commit options
 */
export interface CommitOptions {
  author?: string;
  message: string;
  previousConfig?: any;   // Previous config state (for diffing)
}

/**
 * Diff options
 */
export interface DiffOptions {
  ignoreMetadata?: boolean;  // Ignore metadata changes
  ignoreComments?: boolean;  // Ignore comment changes
}
