// ─── Task Governance ─────────────────────────────────────────────────────────

export interface TaskGovernancePolicy {
  enabled: boolean;
  rules: TaskApprovalRule[];
  defaultTier: ApprovalTier;
  maxPendingTasksPerAgent: number;
  maxTotalActiveTasks: number;
  requireApprovalForPriority: string[];
  /** When true, top-level tasks must reference an approved requirement */
  requireRequirement: boolean;
}

export type ApprovalTier = 'auto' | 'manager' | 'human';

export interface TaskApprovalRule {
  condition: {
    creatorRole?: 'worker' | 'manager';
    priority?: string[];
    titlePattern?: string;
    affectsSharedResource?: boolean;
  };
  tier: ApprovalTier;
}

// ─── System Announcements ────────────────────────────────────────────────────

export type AnnouncementType = 'info' | 'warning' | 'directive' | 'policy_change';
export type AnnouncementPriority = 'normal' | 'high' | 'urgent';
export type AnnouncementScope = 'all' | 'team' | 'role' | 'project';

export interface SystemAnnouncement {
  id: string;
  type: AnnouncementType;
  title: string;
  content: string;
  priority: AnnouncementPriority;
  createdBy: string;
  createdAt: string;
  expiresAt?: string;
  targetScope: AnnouncementScope;
  targetIds?: string[];
  acknowledged: string[];
}

// ─── Task Delivery ───────────────────────────────────────────────────────────

export interface TaskDeliverable {
  type: 'branch' | DeliverableType;
  reference: string;
  summary: string;
  format?: string;
  diffStats?: { filesChanged: number; additions: number; deletions: number };
  testResults?: { passed: number; failed: number; skipped: number };
}

// ─── Unified Deliverable (产出物) ────────────────────────────────────────────

export type DeliverableType = 'file' | 'directory';
export type DeliverableStatus = 'active' | 'verified' | 'outdated';
export type BuilderArtifactType = 'agent' | 'team' | 'skill';

export interface Deliverable {
  id: string;
  type: DeliverableType;
  title: string;
  summary: string;
  reference: string;
  format?: string;
  tags: string[];
  status: DeliverableStatus;
  taskId?: string;
  agentId?: string;
  projectId?: string;
  requirementId?: string;
  artifactType?: BuilderArtifactType;
  artifactData?: Record<string, unknown>;
  diffStats?: { filesChanged: number; additions: number; deletions: number };
  testResults?: { passed: number; failed: number; skipped: number };
  accessCount: number;
  createdAt: string;
  updatedAt: string;
}

// ─── Agent Trust ─────────────────────────────────────────────────────────────

export type TrustLevel = 'probation' | 'standard' | 'trusted' | 'senior';

export interface AgentTrustLevel {
  agentId: string;
  level: TrustLevel;
  score: number;
  totalDeliveries: number;
  acceptedDeliveries: number;
  rejectedDeliveries: number;
  revisionRequests: number;
  consecutiveAcceptances: number;
  lastEvaluatedAt: string;
}

// ─── Archive Policy ──────────────────────────────────────────────────────────

export interface ArchivePolicy {
  autoArchiveAfterDays: number;
  retainTaskLogsForDays: number;
  retainAuditLogsForDays: number;
}

// ─── Report Feedback ─────────────────────────────────────────────────────────

export type FeedbackType = 'annotation' | 'comment' | 'directive';
export type FeedbackDisclosureScope = 'private' | 'targeted' | 'broadcast';

export interface ReportFeedback {
  id: string;
  reportId: string;
  authorId: string;
  authorName: string;
  type: FeedbackType;
  anchor?: {
    section: string;
    itemId?: string;
  };
  content: string;
  priority: 'normal' | 'important' | 'critical';
  disclosure: {
    scope: FeedbackDisclosureScope;
    targetAgentIds?: string[];
    targetTeamIds?: string[];
  };
  actions: FeedbackAction[];
  createdAt: string;
}

export type FeedbackAction =
  | { type: 'announcement'; announcementId: string }
  | { type: 'knowledge'; knowledgeId: string }
  | { type: 'task_created'; taskId: string }
  | { type: 'a2a_message'; targetAgentId: string };
