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 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

    // ============================================================
    // Module Ngân sách (Phase 7) — 4 bảng quản lý ngân sách dự án/gói thầu.
    // 1 root + 3 leaf action (Danh sách / Thao tác / Duyệt).
    // ============================================================
    public const string Budgets = "Budgets";
    public const string BudgetList = "Bg_List";
    public const string BudgetCreate = "Bg_Create";
    public const string BudgetPending = "Bg_Pending";

    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";

    // 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,
        Budgets, BudgetList, BudgetCreate, BudgetPending,
        System, Users, Roles, Permissions, Workflows, PeWorkflows,
    ];

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