/**
 * Shared mock application rows for council list + admin review when API is unavailable.
 */

export type ApplicationStatus =
  | "pending"
  | "approved"
  | "rejected"
  | "transferred"
  | "under_review"
  | "reviewed";

export type ReviewStatus = "not_reviewed" | "under_review" | "reviewed";

export interface Person {
  id: string;
  name: string;
  email?: string;
  phone?: string;
}

export interface ApplicationFile {
  /** Local/API path or relative URL */
  url?: string;
  /** Signed GET (e.g. MinIO full PDF) — prefer when present */
  viewUrl?: string;
  /** Object key when stored in object storage (opaque; for diagnostics) */
  storageKey?: string;
  type?: "pdf" | "docx" | "image" | string;
}

export interface ApplicationItem {
  id: string;
  /** Same as `draft_case_id` from API — Initiative.case_code for loading `/api/v1/application-drafts/…` */
  draftCaseId?: string;
  /** Set by API; mapped to `draftCaseId` in `normalizeApplicationItem` (submission `id` is often `sub-…` instead) */
  draft_case_id?: string;
  submittedDate: string;
  name: string;
  author: Person;
  /** Calendar year of submission (set by API `/api/applications/mine`) */
  calendarYear?: number;
  /** Value key for `DEPARTMENT_OPTIONS` / filter `subjectId` (Đơn vị) */
  subjectId?: string;
  /** Value key for `GROUP_OPTIONS` / filter `topicTypeId` (Nhóm sáng kiến) */
  groupId?: string;
  conference?: { id: string; name: string; subCategory?: string };
  supervisor?: Person | null;
  reviewer?: Person | null;
  reviewDeadline?: string | null;
  /** Legacy display fallback if `groupId` missing */
  topicType?: string;
  /** From draft tab `application` — drives approved-row merit label (2.1.1 / 2.1.2 → Xuất sắc). */
  initiativeClassification?: "technical" | "research" | "textbook" | null;
  /** From draft tab `application` — nhóm 2.2 (sách / tài liệu tham khảo). */
  textbookEvidenceKind?: "" | "book" | "reference";
  status: ApplicationStatus;
  reviewStatus?: ReviewStatus;
  /** Cột «Đủ và Đúng» (danh sách quản trị); API có thể gửi `du_va_dung` */
  duVaDung?: string | null;
  /** Cột «Nhận xét» (thẩm định minh chứng); API có thể gửi `nhan_xet` */
  nhanXet?: string | null;
  files?: {
    abstract?: ApplicationFile | null;
    poster?: ApplicationFile | null;
    fullText?: ApplicationFile | null;
  };
}

export const MOCK_APPLICATIONS: ApplicationItem[] = [
  {
    id: "app-001",
    submittedDate: "2026-03-23T22:23:00Z",
    name: "KHẢO SÁT TÁC DỤNG KHÁNG VIÊM TỪ DƯỢC LIỆU",
    author: { id: "user-042", name: "Lê Thị Kim Ngân", email: "kimngaan1294@gmail.com", phone: "0778093364" },
    subjectId: "khoa_y_te_cong_cong",
    groupId: "innovation_from_research",
    conference: { id: "conf-006", name: "SÁNG THỨ 6", subCategory: "Bệnh không lây nhiễm" },
    supervisor: { id: "user-055", name: "Ngô Văn Hùng" },
    reviewer: { id: "user-101", name: "Phạm Thị Quỳnh" },
    reviewDeadline: "2026-03-31",
    topicType: "Tóm tắt báo cáo khoa học",
    status: "pending",
    reviewStatus: "not_reviewed",
    files: {
      abstract: { url: "/files/app-001/abstract.pdf", type: "pdf" },
      poster: { url: "/files/app-001/poster.docx", type: "docx" },
      fullText: null,
    },
  },
  {
    id: "app-002",
    submittedDate: "2026-03-20T09:10:00Z",
    name: "ỨNG DỤNG AI TRONG DỰ BÁO DỊCH TỄ",
    author: { id: "user-077", name: "Nguyễn Văn Minh", email: "minh@example.com", phone: "0909555000" },
    subjectId: "phong_khoa_hoc_cong_nghe",
    groupId: "internal_technical_management",
    conference: { id: "conf-004", name: "CHIỀU THỨ 5", subCategory: "Dịch tễ học" },
    supervisor: null,
    reviewer: { id: "user-102", name: "Trần Thanh Huyền" },
    reviewDeadline: "2026-03-22",
    topicType: "Nghiên cứu khoa học",
    status: "approved",
    reviewStatus: "reviewed",
    files: {
      abstract: { url: "/files/app-002/abstract.pdf", type: "pdf" },
      poster: null,
      fullText: { url: "/files/app-002/full-text", type: "link" },
    },
  },
];

export function getMockApplicationById(id: string): ApplicationItem | undefined {
  return MOCK_APPLICATIONS.find((a) => a.id === id);
}
