namespace ERPCore.System.Errors;

/// <summary>
/// Stable domain error codes carried in the <c>code</c> extension of RFC 7807
/// ProblemDetails responses. The authoritative catalog lives in
/// docs/11-BACKEND-PHASE1.md §7; add codes here as endpoints are implemented so
/// the two stay in sync.
/// </summary>
public static class ErrorCodes
{
    // Generic (framework-level) helpers used by the exception types below.
    public const string Validation = "validation_error";
    public const string NotFound = "not_found";
    public const string Conflict = "conflict";

    // Catalog (docs/11 §7) — exact strings surfaced to clients.
    public const string SkuDuplicate = "SKU_DUPLICATE";
    public const string MasterInUse = "MASTER_IN_USE";
    public const string PoNotEditable = "PO_NOT_EDITABLE";
    public const string OverReceiptTolerance = "OVER_RECEIPT_TOLERANCE";
    public const string StockNegativeBlocked = "STOCK_NEGATIVE_BLOCKED";
    public const string ExpiredBatchBlocked = "EXPIRED_BATCH_BLOCKED";
    public const string OnHoldNotIssuable = "ONHOLD_NOT_ISSUABLE";
    public const string ReasonCodeRequired = "REASON_CODE_REQUIRED";
    public const string ConcurrencyConflict = "CONCURRENCY_CONFLICT";
    public const string IdempotencyReplay = "IDEMPOTENCY_REPLAY";
    public const string ConfigDisabled = "CONFIG_DISABLED";
    public const string RoleInUse = "ROLE_IN_USE";

    // Auth proxy (AuthController → AuthHex, docs/11 §2.0)
    public const string AuthUpstreamError = "AUTH_UPSTREAM_ERROR";
    public const string AuthServiceUnavailable = "AUTH_SERVICE_UNAVAILABLE";
    public const string CsrfTokenMismatch = "CSRF_TOKEN_MISMATCH";
    public const string RefreshTokenMissing = "REFRESH_TOKEN_MISSING";

    // HRM (docs/13-BACKEND-HRM-API.md §7)
    public const string EmployeeCodeDuplicate = "EMPLOYEE_CODE_DUPLICATE";
    public const string EmployeeAlreadyLinked = "EMPLOYEE_ALREADY_LINKED";
    public const string UserAlreadyLinked = "USER_ALREADY_LINKED";
    public const string DepartmentCycleDetected = "DEPARTMENT_CYCLE_DETECTED";
    public const string DocumentTypeInUse = "DOCUMENT_TYPE_IN_USE";
    public const string FileTypeNotAllowed = "FILE_TYPE_NOT_ALLOWED";
    public const string FileTooLarge = "FILE_TOO_LARGE";
    public const string AttendanceBatchLocked = "ATTENDANCE_BATCH_LOCKED";
    public const string AttendanceDuplicateUnresolved = "ATTENDANCE_DUPLICATE_UNRESOLVED";
    public const string AttendanceNotConfirmed = "ATTENDANCE_NOT_CONFIRMED";
    public const string SalaryStructureOverlap = "SALARY_STRUCTURE_OVERLAP";
    public const string TaxSlabGapInvalid = "TAX_SLAB_GAP_INVALID";
    public const string PayrollPeriodLocked = "PAYROLL_PERIOD_LOCKED";

    // Manufacturing / Production Lines (docs/30-BACKEND-PHASE2.md §D.4)
    public const string TemplateInUse = "TEMPLATE_IN_USE";
    public const string TemplateInactive = "TEMPLATE_INACTIVE";
    public const string GraphCycle = "GRAPH_CYCLE";
    public const string GraphTerminalCount = "GRAPH_TERMINAL_COUNT";
    public const string GraphDisconnected = "GRAPH_DISCONNECTED";
    public const string GraphInputSourceInvalid = "GRAPH_INPUT_SOURCE_INVALID";
    public const string TerminalOutputItemRequired = "TERMINAL_OUTPUT_ITEM_REQUIRED";
    public const string WipUnitRequired = "WIP_UNIT_REQUIRED";
    public const string StageNotReady = "STAGE_NOT_READY";
    public const string StageNotInProgress = "STAGE_NOT_IN_PROGRESS";
    public const string StageNotDone = "STAGE_NOT_DONE";
    public const string StageNotEditable = "STAGE_NOT_EDITABLE";
    public const string StageRejectInvalid = "STAGE_REJECT_INVALID";
    public const string RequiredFieldMissing = "REQUIRED_FIELD_MISSING";
    public const string TransferExceedsAvailable = "TRANSFER_EXCEEDS_AVAILABLE";
    public const string LeftoverExceedsConsumed = "LEFTOVER_EXCEEDS_CONSUMED";
    public const string RunCostClosed = "RUN_COST_CLOSED";
    public const string RunNotCancellable = "RUN_NOT_CANCELLABLE";

    // General Ledger service proxy (GeneralLedgerController → external GL service, docs/12)
    public const string GlServiceUnavailable = "GL_SERVICE_UNAVAILABLE";
    // General Ledger typed internal calls (GRN receipt/payment posting, docs/12 §5's deferred work)
    public const string GlRequestFailed = "GL_REQUEST_FAILED";

    // GRN payments
    public const string GrnNotPayable = "GRN_NOT_PAYABLE";
    public const string GrnPaymentExceedsBalance = "GRN_PAYMENT_EXCEEDS_BALANCE";
    public const string GrnBankAccountNotFound = "GRN_BANK_ACCOUNT_NOT_FOUND";

    // Sales invoice payments
    public const string SalesInvoiceNotPayable = "SALES_INVOICE_NOT_PAYABLE";
    public const string SalesInvoicePaymentExceedsBalance = "SALES_INVOICE_PAYMENT_EXCEEDS_BALANCE";
    public const string SalesInvoiceBankAccountNotFound = "SALES_INVOICE_BANK_ACCOUNT_NOT_FOUND";
}
