/**
 * Types for the Trust Engine — graduated autonomy based on track record.
 */

/** Tool risk categories */
export type ToolCategory = 'read' | 'write' | 'execute' | 'external'

/** Trust score for a single tool category */
export interface CategoryTrust {
  successes: number
  failures: number
  lastFailure?: number
  score: number // 0.0 - 1.0
}

/** Per-project trust profile */
export interface TrustProfile {
  projectPath: string
  tools: Record<ToolCategory, CategoryTrust>
  lastUpdated: number
}

/** Trust state persisted to disk */
export interface TrustState {
  version: 1
  profiles: Record<string, TrustProfile> // keyed by project path
}

/** Default trust scores for a new category */
export function createDefaultCategoryTrust(): CategoryTrust {
  return {
    successes: 0,
    failures: 0,
    score: 0.0,
  }
}

/** Create a fresh trust profile for a project */
export function createDefaultTrustProfile(
  projectPath: string,
): TrustProfile {
  return {
    projectPath,
    tools: {
      read: createDefaultCategoryTrust(),
      write: createDefaultCategoryTrust(),
      execute: createDefaultCategoryTrust(),
      external: createDefaultCategoryTrust(),
    },
    lastUpdated: Date.now(),
  }
}

export function createFreshTrustState(): TrustState {
  return {
    version: 1,
    profiles: {},
  }
}
