// 資料庫模型定義
export interface User {
  id: number;
  email: string;
  username: string;
  password_hash: string;
  full_name?: string;
  avatar_url?: string;
  role: 'admin' | 'user';
  is_active: boolean;
  email_verified_at?: Date;
  last_login_at?: Date;
  created_at: Date;
  updated_at: Date;
}

export interface CriteriaTemplate {
  id: number;
  user_id: number;
  name: string;
  description?: string;
  is_default: boolean;
  is_public: boolean;
  total_weight: number;
  created_at: Date;
  updated_at: Date;
}

export interface CriteriaItem {
  id: number;
  template_id: number;
  name: string;
  description?: string;
  weight: number;
  max_score: number;
  sort_order: number;
  created_at: Date;
  updated_at: Date;
}

export interface Project {
  id: number;
  user_id: number;
  template_id: number;
  title: string;
  description?: string;
  status: 'draft' | 'uploading' | 'analyzing' | 'completed' | 'failed';
  analysis_started_at?: Date;
  analysis_completed_at?: Date;
  created_at: Date;
  updated_at: Date;
}

export interface ProjectFile {
  id: number;
  project_id: number;
  original_name: string;
  file_name: string;
  file_path: string;
  file_size: number;
  file_type: string;
  mime_type: string;
  upload_status: 'uploading' | 'completed' | 'failed';
  upload_progress: number;
  created_at: Date;
  updated_at: Date;
}

export interface ProjectWebsite {
  id: number;
  project_id: number;
  url: string;
  title?: string;
  description?: string;
  status: 'pending' | 'analyzing' | 'completed' | 'failed';
  created_at: Date;
  updated_at: Date;
}

export interface Evaluation {
  id: number;
  project_id: number;
  overall_score?: number;
  max_possible_score: number;
  grade?: string;
  analysis_duration?: number;
  ai_model_version?: string;
  status: 'pending' | 'analyzing' | 'completed' | 'failed';
  error_message?: string;
  created_at: Date;
  updated_at: Date;
}

export interface EvaluationScore {
  id: number;
  evaluation_id: number;
  criteria_item_id: number;
  score: number;
  max_score: number;
  weight: number;
  weighted_score: number;
  percentage: number;
  created_at: Date;
}

export interface EvaluationFeedback {
  id: number;
  evaluation_id: number;
  criteria_item_id?: number;
  feedback_type: 'overall' | 'criteria' | 'strength' | 'improvement';
  content: string;
  sort_order: number;
  created_at: Date;
}

export interface SystemSetting {
  id: number;
  setting_key: string;
  setting_value?: string;
  description?: string;
  created_at: Date;
  updated_at: Date;
}

// 查詢結果類型
export interface ProjectWithDetails extends Project {
  template: CriteriaTemplate;
  files: ProjectFile[];
  websites: ProjectWebsite[];
  evaluation?: Evaluation;
}

export interface EvaluationWithDetails extends Evaluation {
  project: Project;
  scores: (EvaluationScore & { criteria_item: CriteriaItem })[];
  feedback: EvaluationFeedback[];
}

export interface CriteriaTemplateWithItems extends CriteriaTemplate {
  items: CriteriaItem[];
}
