/**
 * Core TypeScript types for the Project Management App
 * These types map directly to Firestore collections
 */

// ============================================
// Enums for Status and Priority
// ============================================

export type ProjectStatus = 'planned' | 'active' | 'completed';

export type TaskStatus = 'todo' | 'inprogress' | 'review' | 'done';

export type TaskPriority = 'low' | 'medium' | 'high';

export type ActivityAction =
  | 'project_created'
  | 'project_updated'
  | 'project_deleted'
  | 'task_created'
  | 'task_updated'
  | 'task_deleted'
  | 'task_moved'
  | 'comment_added'
  | 'file_uploaded'
  | 'subtask_added'
  | 'subtask_completed';

// ============================================
// Base Types
// ============================================

export interface Timestamp {
  seconds: number;
  nanoseconds: number;
}

export interface BaseEntity {
  id: string;
  createdAt: Date;
  updatedAt: Date;
}

// ============================================
// Project Types
// ============================================

export interface Project extends BaseEntity {
  name: string;
  description: string;
  status: ProjectStatus;
  startDate: Date;
  endDate: Date;
  color?: string; // Optional color for project identification
  taskCount?: number; // Cached task count
  completedTaskCount?: number; // Cached completed task count
}

export interface ProjectFormData {
  name: string;
  description: string;
  status: ProjectStatus;
  startDate: Date;
  endDate: Date;
  color?: string;
}

// ============================================
// Task Types
// ============================================

export interface Subtask {
  id: string;
  title: string;
  completed: boolean;
  createdAt: Date;
}

export interface Task extends BaseEntity {
  projectId: string;
  title: string;
  description: string;
  status: TaskStatus;
  priority: TaskPriority;
  dueDate: Date;
  assignedTo: string; // Name or identifier
  subtasks: Subtask[];
  attachments: FileAttachment[];
  order: number; // For ordering within a status column
}

export interface TaskFormData {
  projectId: string;
  title: string;
  description: string;
  status: TaskStatus;
  priority: TaskPriority;
  dueDate: Date;
  assignedTo: string;
}

// ============================================
// Comment Types
// ============================================

export interface Comment extends BaseEntity {
  taskId: string;
  projectId: string;
  authorName: string;
  content: string;
  attachments?: FileAttachment[];
}

export interface CommentFormData {
  taskId: string;
  projectId: string;
  authorName: string;
  content: string;
}

// ============================================
// Activity Log Types
// ============================================

export interface ActivityLog extends BaseEntity {
  projectId: string;
  taskId?: string;
  action: ActivityAction;
  actorName: string;
  description: string;
  metadata?: Record<string, unknown>;
}

// ============================================
// File Attachment Types
// ============================================

export interface FileAttachment {
  id: string;
  name: string;
  url: string;
  size: number;
  type: string;
  uploadedAt: Date;
  uploadedBy: string;
}

// ============================================
// Dashboard Analytics Types
// ============================================

export interface DashboardStats {
  totalProjects: number;
  activeProjects: number;
  completedProjects: number;
  plannedProjects: number;
  totalTasks: number;
  tasksByStatus: {
    todo: number;
    inprogress: number;
    review: number;
    done: number;
  };
  overdueTasks: number;
  projectProgress: ProjectProgress[];
}

export interface ProjectProgress {
  projectId: string;
  projectName: string;
  totalTasks: number;
  completedTasks: number;
  progressPercentage: number;
}

// ============================================
// UI Helper Types
// ============================================

export interface SelectOption {
  value: string;
  label: string;
}

export interface KanbanColumn {
  id: TaskStatus;
  title: string;
  tasks: Task[];
}

// Status and Priority display configurations
export const PROJECT_STATUS_CONFIG: Record<
  ProjectStatus,
  { label: string; color: string }
> = {
  planned: { label: 'Planned', color: 'bg-status-planned' },
  active: { label: 'Active', color: 'bg-status-active' },
  completed: { label: 'Completed', color: 'bg-status-completed' },
};

export const TASK_STATUS_CONFIG: Record<
  TaskStatus,
  { label: string; color: string }
> = {
  todo: { label: 'To Do', color: 'bg-status-todo' },
  inprogress: { label: 'In Progress', color: 'bg-status-inprogress' },
  review: { label: 'Review', color: 'bg-status-review' },
  done: { label: 'Done', color: 'bg-status-done' },
};

export const TASK_PRIORITY_CONFIG: Record<
  TaskPriority,
  { label: string; color: string }
> = {
  low: { label: 'Low', color: 'bg-priority-low' },
  medium: { label: 'Medium', color: 'bg-priority-medium' },
  high: { label: 'High', color: 'bg-priority-high' },
};

// Project color options
export const PROJECT_COLORS = [
  '#8B5CF6', // Purple
  '#3B82F6', // Blue
  '#10B981', // Green
  '#F59E0B', // Amber
  '#EF4444', // Red
  '#EC4899', // Pink
  '#06B6D4', // Cyan
  '#6366F1', // Indigo
] as const;

