import type { TaskIssueEntry } from '../lib/taskIssues';

export type Role = 'ADMIN' | 'MANAGER' | 'MEMBER';
export type { TaskIssueEntry };
export type TaskStatus = 'TODO' | 'IN_PROGRESS' | 'REVIEW' | 'DONE' | 'CANCELLED';
export type Priority = 'LOW' | 'MEDIUM' | 'HIGH' | 'URGENT';

export interface User {
  id: string;
  email: string;
  name: string;
  role: Role;
  department: string | null;
  isActive: boolean;
  createdAt: string;
}

export interface TeamMember {
  id: string;
  name: string;
  rank: string | null;
  role: string | null;
  cell: string | null;
  contact: string | null;
  photoUrl: string | null;
  sortOrder?: number;
  isActive?: boolean;
}

export type TeamMemberBrief = Pick<
  TeamMember,
  'id' | 'name' | 'rank' | 'role' | 'cell' | 'contact' | 'photoUrl'
>;

export interface Task {
  id: string;
  title: string;
  description: string | null;
  detailDescription?: string | null;
  status: TaskStatus;
  priority: Priority;
  quarter: string;
  category: string | null;
  section: string | null;      // HR | 운영관리
  tag: string | null;          // Growth | Policy | Performance | Culture | Asset | Space | Safety | Environment
  taskType: string | null;     // 상시업무 | 프로젝트
  progress: number;            // 0-100
  issueNote: string | null;
  issueEntries?: TaskIssueEntry[] | null;
  startDate: string | null;
  dueDate: string | null;
  showDate: boolean;
  showDescription: boolean;
  showStatus: boolean;
  showIssue: boolean;
  showProgress: boolean;
  creatorId: string;
  assigneeId: string | null;
  pmMemberId?: string | null;
  createdAt: string;
  updatedAt: string;
  assignee?: Pick<User, 'id' | 'name' | 'department'> | null;
  creator?: Pick<User, 'id' | 'name'>;
  pmMember?: TeamMemberBrief | null;
  assigneeMembers?: TeamMemberBrief[];
  milestones?: Milestone[];
  _count?: { files: number; details: number };
}

export interface TaskDetail {
  id: string;
  taskId: string;
  milestoneId: string | null;
  content: string;
  authorName: string | null;
  updatedBy: string;
  createdAt: string;
  updatedAt: string;
  author?: Pick<User, 'id' | 'name'>;
}

export interface MilestoneLink {
  label: string;
  url: string;
}

export interface KpiMetric {
  id: string;
  taskId: string;
  quarter: string;
  target: number;
  actual: number;
  unit: string | null;
}

export interface FileRecord {
  id: string;
  taskId: string;
  milestoneId: string | null;
  filename: string;
  originalName: string;
  displayName: string | null;
  sortOrder: number;
  mimetype: string;
  size: number;
  path: string;
  uploadedBy: string;
  createdAt: string;
}

export interface MilestonePeriodEntry {
  id: string;
  startDate: string;
  dueDate: string;
  note: string;
}

export interface Milestone {
  id: string;
  taskId: string;
  title: string;
  subtitle?: string | null;
  description: string | null;
  startDate: string | null;
  dueDate: string | null;
  periodEntries?: MilestonePeriodEntry[] | null;
  progress: number;
  links: string | null;
  completedAt: string | null;
  order: number;
  pmMemberId?: string | null;
  pmMember?: TeamMemberBrief | null;
  assigneeMembers?: TeamMemberBrief[];
  createdAt: string;
  updatedAt: string;
}

export interface TaskFull extends Task {
  details: TaskDetail[];
  kpiMetrics: KpiMetric[];
  files: FileRecord[];
  milestones: Milestone[];
}
