namespace SolutionErp.Domain.Identity;

// Nguồn duy nhất (single source of truth) cho menu key — dùng ở cả BE (policy) và seed.
// FE có `src/lib/menuKeys.ts` đồng bộ tay.
public static class MenuKeys
{
    public const string Dashboard = "Dashboard";
    public const string Master = "Master";
    public const string Suppliers = "Suppliers";
    public const string Projects = "Projects";
    public const string Departments = "Departments";
    public const string Contracts = "Contracts";
    public const string Forms = "Forms";
    public const string Reports = "Reports";
    public const string System = "System";
    public const string Users = "Users";
    public const string Roles = "Roles";
    public const string Permissions = "Permissions";
    public const string MenuVisibility = "MenuVisibility";    // [Mig 27] admin Ẩn/Hiện + Đổi tên menu fe-user
    public const string Workflows = "Workflows";

    // 4 master catalogs cho Details add form (autocomplete) — admin CRUD
    public const string Catalogs = "Catalogs";              // group
    public const string CatalogUnits = "CatalogUnits";
    public const string CatalogMaterials = "CatalogMaterials";
    public const string CatalogServices = "CatalogServices";
    public const string CatalogWorkItems = "CatalogWorkItems";

    // Per-contract-type menu groups + 3 action leaves each.
    // Key format: Ct_<TypeCode>[_<Action>] — prefix `Ct_` distinguishes from
    // top-level. Menu tree endpoint (GetMyMenuTreeQuery) treats descendants of
    // `Contracts` as inheriting the parent permission so we don't need per-
    // child permission rows for all roles.
    public static readonly string[] ContractTypeCodes =
        ["ThauPhu", "GiaoKhoan", "NhaCungCap", "DichVu", "MuaBan", "NguyenTacNcc", "NguyenTacDv"];

    public static string ContractTypeGroup(string typeCode) => $"Ct_{typeCode}";
    public static string ContractTypeList(string typeCode) => $"Ct_{typeCode}_List";
    public static string ContractTypeCreate(string typeCode) => $"Ct_{typeCode}_Create";
    public static string ContractTypePending(string typeCode) => $"Ct_{typeCode}_Pending";

    // Workflow admin per ContractType — sub-menu dưới `Workflows`, click leaf
    // → mở /system/workflows/{typeCode} (filter theo type thay vì tab).
    public static string WorkflowTypeLeaf(string typeCode) => $"Wf_{typeCode}";

    // ============================================================
    // Module Duyệt NCC (tiền-HĐ) — Pe_* prefix. 2 EvaluationType:
    //   DuyetNcc (A, NccOnly 3-step) + DuyetNccPhuongAn (B, NccWithPlan 5-step).
    // Mỗi type có 3 action leaf (Danh sách / Thao tác / Duyệt) + 1 group.
    // Workflow admin cho PE ở /system/pe-workflows/:typeCode.
    // ============================================================
    public const string PurchaseEvaluations = "PurchaseEvaluations";          // root group
    public const string PeWorkflows = "PeWorkflows";                           // workflow admin root

    // ============================================================
    // Quy trình duyệt MỚI (Mig 22 — Session 17, 2026-05-08):
    // Schema riêng `ApprovalWorkflow` để UAT trước khi migrate hoàn toàn.
    // Cấu trúc: Quy trình > Bước (Phòng) > Cấp (NV cụ thể).
    //   Mã + Tên Quy trình
    //   Bước 1 - Phòng A
    //     Cấp 1 - NV X
    //     Cấp 2 - NV Y
    //   Bước 2 - Phòng B
    //     ...
    // ============================================================
    public const string ApprovalWorkflowsV2 = "ApprovalWorkflowsV2";          // root admin (mới)
    public const string ApprovalWorkflowDuyetNccV2 = "AwV2_DuyetNcc";          // leaf cho Duyệt NCC mới
    public const string ApprovalWorkflowDuyetNccPhuongAnV2 = "AwV2_DuyetNccPhuongAn";  // leaf cho Duyệt NCC và Giải pháp mới

    // [S61 Mig 50] Module Ngân sách cũ (Budgets + Bg_List/Bg_Create/Bg_Pending)
    // đã XÓA — thay bằng "Ngân sách gói thầu" nhúng trong phiếu PE
    // (PeWorkItemBudgets per cặp Dự án × Hạng mục). Menu/Permission rows cũ
    // cleanup qua SQL trong migration ReplaceBudgetModuleWithPeWorkItemBudgets.

    // ============================================================
    // Module Nhân sự (Phase 10.1 G-H1 — Mig 34 S33 2026-05-26).
    // Port từ NamGroup CT_NHANSU 1675 NV. 1 root group + 1 leaf Hồ sơ NS.
    // Phase 1 minimal scope — satellite CRUD endpoint defer Phase 1.5.
    // Future Phase 10.4 add: Hrm_Dashboard (G-H3) + Hrm_Config* (G-H2).
    // ============================================================
    public const string Hrm = "Hrm";                                // root group
    public const string HrmHoSo = "Hrm_HoSo";                       // Hồ sơ Nhân sự (list + detail + edit)
    // Phase 10.2 G-H2 (Mig 35 — S34) — Cấu hình HRM 4 catalog lookup.
    public const string HrmConfig = "Hrm_Config";                          // sub-group cấu hình
    public const string HrmConfigLeaveTypes = "Hrm_Config_LeaveTypes";     // Loại phép
    public const string HrmConfigHolidays = "Hrm_Config_Holidays";         // Ngày lễ
    public const string HrmConfigShifts = "Hrm_Config_Shifts";             // Ca làm việc
    public const string HrmConfigOtPolicies = "Hrm_Config_OtPolicies";     // Chính sách OT
    // Phase 11 P11-C (Mig 44 — S51) — Danh mục xe công + tài xế (reference VehicleBooking).
    public const string HrmConfigVehicles = "Hrm_Config_Vehicles";         // Xe công
    public const string HrmConfigDrivers = "Hrm_Config_Drivers";           // Tài xế

    // ============================================================
    // Module Văn phòng số (Phase 10.2 G-O1+ S34 2026-05-27).
    // 1 root group `Off` + leaf con: Off_DanhBa (G-O1 Danh bạ nội bộ).
    // Future Phase 10.2+ add: Off_PhongHop (G-O2 booking) +
    // workflow apps Off_DeXuat / Off_DonTu / Off_DatXe / Off_ItTicket.
    // ============================================================
    public const string Off = "Off";                                // root group văn phòng số
    public const string OffDashboard = "Off_Dashboard";            // Bảng điều khiển Văn phòng số (landing, S? — admin auto via All)
    public const string OffDanhBa = "Off_DanhBa";                   // Danh bạ nội bộ (card grid)
    // Phase 10.2 G-O2 (Mig 36 — S36 2026-05-28) — Phòng họp + Booking calendar.
    public const string OffPhongHop = "Off_PhongHop";                          // sub-group phòng họp
    public const string OffPhongHopView = "Off_PhongHop_View";                 // Xem lịch (FullCalendar)
    public const string OffPhongHopManage = "Off_PhongHop_Manage";             // Quản lý phòng (Admin CRUD MeetingRoom)
    public const string OffPhongHopBook = "Off_PhongHop_Book";                 // Đặt phòng (Create/Update/Cancel Booking)

    // Phase 10.3 G-O3 (Mig 38 — S37 2026-05-28) — Đề xuất (Proposal) workflow V2.
    public const string OffDeXuat = "Off_DeXuat";                              // sub-group Đề xuất
    public const string OffDeXuatList = "Off_DeXuat_List";                     // Danh sách đề xuất
    public const string OffDeXuatCreate = "Off_DeXuat_Create";                 // Tạo đề xuất mới
    public const string OffDeXuatInbox = "Off_DeXuat_Inbox";                   // Inbox phê duyệt

    // Phase 10.3-10.4 G-O4+G-O5+G-O6+G-P1 (Mig 39+40 — S38 2026-05-28) — Skeleton Workflow Apps.
    public const string OffDonTu = "Off_DonTu";                                // sub-group Đơn từ
    public const string OffDonTuLeave = "Off_DonTu_Leave";                     // Đơn nghỉ phép
    public const string OffDonTuOt = "Off_DonTu_Ot";                           // Đơn OT
    public const string OffDonTuTravel = "Off_DonTu_Travel";                   // Đơn công tác
    public const string OffDatXe = "Off_DatXe";                                // Đặt xe công
    public const string OffItTicket = "Off_ItTicket";                          // Ticket CNTT helpdesk
    public const string OffChamCong = "Off_ChamCong";                          // Chấm công GPS (G-P1) — [S57] re-parent Off → Personal
    public const string OffAttendanceReport = "Off_AttendanceReport";          // Báo cáo chấm công (P11-E, admin)
    public const string HrmDashboard = "Hrm_Dashboard";                        // Dashboard HRM (G-H3)

    // ============================================================
    // [S57] Nhóm "Cá nhân" — mirror layout Puro (NAMGROUP). Root group cho mục
    // cá nhân nhân viên. "Chấm công" (Off_ChamCong) re-parent Off → Personal.
    // ============================================================
    public const string Personal = "Personal";                                 // root group "Cá nhân"

    public static readonly string[] PurchaseEvaluationTypeCodes =
        ["DuyetNcc", "DuyetNccPhuongAn"];

    public static string PurchaseEvaluationGroup(string typeCode) => $"Pe_{typeCode}";
    public static string PurchaseEvaluationList(string typeCode) => $"Pe_{typeCode}_List";
    public static string PurchaseEvaluationCreate(string typeCode) => $"Pe_{typeCode}_Create";
    public static string PurchaseEvaluationPending(string typeCode) => $"Pe_{typeCode}_Pending";
    // [Plan AA S24 t1] User read-only view ma trận phân quyền của workflow V2
    // admin Designer đã ghim (IsUserSelectable=true). Suffix `_WfView` distinct
    // với admin `PeWf_*` (Designer write).
    public static string PurchaseEvaluationWorkflowView(string typeCode) => $"Pe_{typeCode}_WfView";

    // Workflow admin leaf per PE type — dưới PeWorkflows, click leaf mở
    // /system/pe-workflows/{typeCode}
    public static string PeWorkflowTypeLeaf(string typeCode) => $"PeWf_{typeCode}";

    public static readonly string[] All =
    [
        Dashboard,
        Master, Suppliers, Projects, Departments,
        Catalogs, CatalogUnits, CatalogMaterials, CatalogServices, CatalogWorkItems,
        Contracts, Forms, Reports,
        PurchaseEvaluations,
        Hrm, HrmHoSo,                                                                            // Mig 34 — Phase 10.1
        HrmConfig, HrmConfigLeaveTypes, HrmConfigHolidays, HrmConfigShifts, HrmConfigOtPolicies, // Mig 35 — Phase 10.2 G-H2
        HrmConfigVehicles, HrmConfigDrivers,                                                     // Mig 44 — Phase 11 P11-C
        Off, OffDashboard, OffDanhBa,                                                            // Phase 10.2 G-O1 — Văn phòng số (+Off_Dashboard landing)
        OffPhongHop, OffPhongHopView, OffPhongHopManage, OffPhongHopBook,                        // Phase 10.2 G-O2 — Phòng họp
        OffDeXuat, OffDeXuatList, OffDeXuatCreate, OffDeXuatInbox,                               // Phase 10.3 G-O3 — Đề xuất
        OffDonTu, OffDonTuLeave, OffDonTuOt, OffDonTuTravel,                                      // Phase 10.3 G-O4 — Đơn từ
        OffDatXe, OffItTicket, OffChamCong, OffAttendanceReport, HrmDashboard,                    // Phase 10.3-10.4 — G-O5/G-O6/G-P1/G-H3 + P11-E report
        Personal,                                                                                // [S57] Cá nhân (Puro grouping — Chấm công re-parent)
        System, Users, Roles, Permissions, MenuVisibility, Workflows, PeWorkflows,
        ApprovalWorkflowsV2, ApprovalWorkflowDuyetNccV2, ApprovalWorkflowDuyetNccPhuongAnV2,    // Mig 22
    ];

    public static readonly string[] Actions = ["Read", "Create", "Update", "Delete"];
}
