export interface Project {
  id: string;
  name: string;
  path: string;
  cloned_from: string | null;
  base_branch: string;
  created_at: string;
}

export interface TuleapCredentialsSafe {
  id: string;
  project_id: string | null;
  tuleap_url: string;
  username: string;
}

export type AgentRole = "analyst" | "developer";
export type AgentTool = "codex" | "claude_code";

export interface Agent {
  id: string;
  name: string;
  role: AgentRole;
  tool: AgentTool;
  custom_prompt: string;
  is_default: boolean;
  created_at: string;
  updated_at: string;
}

export interface Filter {
  field: string;
  operator: string;
  value: string[];
}

export interface FilterGroup {
  conditions: Filter[];
}

export interface TrackerField {
  field_id: number;
  label: string;
  field_type: string;
  values: FieldValue[];
}

export interface FieldValue {
  id: number;
  label: string;
}

export interface WatchedTracker {
  id: string;
  project_id: string;
  tracker_id: number;
  tracker_label: string;
  polling_interval: number;
  analyst_agent_id: string | null;
  developer_agent_id: string | null;
  filters: FilterGroup[];
  enabled: boolean;
  status: string;
  last_polled_at: string | null;
  created_at: string;
}

export interface ProcessedTicket {
  id: string;
  tracker_id: string | null;
  project_id: string;
  source: string;
  source_ref: string | null;
  artifact_id: number;
  artifact_title: string;
  artifact_data: string;
  status: string;
  analyst_report: string | null;
  developer_report: string | null;
  worktree_path: string | null;
  branch_name: string | null;
  detected_at: string;
  processed_at: string | null;
}

export interface GraylogCredentialsSafe {
  id: string;
  project_id: string;
  base_url: string;
  analyst_agent_id: string;
  developer_agent_id: string;
  stream_id: string | null;
  query_filter: string;
  polling_interval_minutes: number;
  lookback_minutes: number;
  score_threshold: number;
  created_at: string;
  updated_at: string;
}

export interface GraylogSubject {
  id: string;
  project_id: string;
  subject_key: string;
  source: string;
  normalized_message: string;
  first_seen_at: string;
  last_seen_at: string;
  last_score: number;
  active_ticket_id: string | null;
  status: string;
  created_at: string;
  updated_at: string;
}

export interface GraylogDetection {
  id: string;
  subject_id: string;
  window_start: string;
  window_end: string;
  critical_count: number;
  error_count: number;
  warning_count: number;
  total_count: number;
  last_seen_at: string;
  score: number;
  triggered: boolean;
  triggered_ticket_id: string | null;
  created_at: string;
}

export interface ProjectThroughputStats {
  backlog_count: number;
  done_last_24h: number;
  error_last_24h: number;
  avg_lead_time_seconds: number | null;
}

export interface Worktree {
  id: string;
  ticket_id: string;
  path: string;
  branch_name: string;
  status: string;
  created_at: string;
  merged_at: string | null;
  merged_into: string | null;
}

export interface TicketResult {
  ticket: ProcessedTicket;
  worktree: Worktree | null;
}

export interface OrchaiNotification {
  id: string;
  project_id: string;
  ticket_id: string | null;
  notification_type: string;
  title: string;
  message: string;
  read: boolean;
  created_at: string;
}

export interface ProjectModule {
  id: string;
  project_id: string;
  module_key: string;
  name: string;
  description: string;
  enabled: boolean;
  config_json: string;
  created_at: string;
  updated_at: string;
}

export interface LiveSession {
  id: string;
  project_id: string;
  agent_id: string;
  title: string;
  status: string;
  created_at: string;
  updated_at: string;
}

export interface LiveMessage {
  id: string;
  session_id: string;
  sender: string;
  content: string;
  created_at: string;
}

export interface LiveAgentExchange {
  user_message: LiveMessage;
  agent_message: LiveMessage;
}

export interface AgentTask {
  id: string;
  project_id: string;
  agent_id: string;
  title: string;
  description: string;
  status: string;
  result: string | null;
  error: string | null;
  created_at: string;
  started_at: string | null;
  finished_at: string | null;
}
