namespace PowderCoating.Shared.Constants;

public static class AppConstants
{
    public const string ApplicationName = "Powder Coating Logix";
    public const string Version = "1.0.0";

    /// <summary>Set to true to enable SMS features throughout the UI.</summary>
    public const bool SmsEnabled = false;

    /// <summary>
    /// Current version of the SMS terms of service. Incrementing this string invalidates all
    /// existing company agreements and forces company admins to re-accept before enabling SMS.
    /// </summary>
    public const string SmsTermsVersion = "1.0";
    
    public static class Roles
    {
        // System-level roles
        public const string SuperAdmin = "SuperAdmin";  // Platform administrator

        // Legacy company-level roles (deprecated - use CompanyRole field instead)
        public const string Administrator = "Administrator";
        public const string Manager = "Manager";
        public const string Employee = "Employee";
        public const string ShopFloor = "ShopFloor";
        public const string ReadOnly = "ReadOnly";
    }

    public static class CompanyRoles
    {
        public const string CompanyAdmin = "CompanyAdmin";
        public const string Manager = "Manager";
        public const string Accountant = "Accountant";
        public const string Worker = "Worker";
        public const string Viewer = "Viewer";
    }
    
    public static class Policies
    {
        // System-level policies
        public const string SuperAdminOnly = "SuperAdminOnly";
        public const string CompanyAdminOnly = "CompanyAdminOnly";
        public const string CanManageUsers = "CanManageUsers";
        public const string CanViewData = "CanViewData";

        // Permission-based policies
        public const string CanManageJobs = "CanManageJobs";
        public const string CanManageInventory = "CanManageInventory";
        public const string CanManageCustomers = "CanManageCustomers";
        public const string CanCreateQuotes = "CanCreateQuotes";
        public const string CanManageCalendar = "CanManageCalendar";
        public const string CanViewCalendar = "CanViewCalendar";
        public const string CanManageProducts = "CanManageProducts";
        public const string CanViewProducts = "CanViewProducts";
        public const string CanManageEquipment = "CanManageEquipment";
        public const string CanManageVendors = "CanManageVendors";
        public const string CanManagePurchaseOrders = "CanManagePurchaseOrders";
        public const string CanManageMaintenance = "CanManageMaintenance";
        public const string CanManageInvoices = "CanManageInvoices";
        public const string CanViewReports = "CanViewReports";
        public const string CanManageBills = "CanManageBills";
        public const string CanManageAccounting = "CanManageAccounting";
    }
    
    public static class FileUpload
    {
        public const long MaxFileSize = 10 * 1024 * 1024; // 10 MB
        public static readonly string[] AllowedImageExtensions = { ".jpg", ".jpeg", ".png", ".gif", ".webp" };
        public static readonly string[] AllowedDocumentExtensions = { ".pdf", ".doc", ".docx", ".xls", ".xlsx" };
    }
    
    public static class Pagination
    {
        public const int DefaultPageSize = 25;
        public const int MaxPageSize = 100;
    }

    public static class SubscriptionConstants
    {
        public const int GracePeriodDays = 14;
        public const int UnlimitedValue = -1;
    }
    
    public static class RateLimitPolicies
    {
        public const string Auth           = "rl_auth";
        public const string Registration   = "rl_registration";
        public const string Public         = "rl_public";
        public const string Webhook        = "rl_webhook";
        public const string Ai             = "rl_ai";
        public const string Authenticated  = "rl_authenticated";
    }

    /// <summary>
    /// Canonical feature identifiers written to AiUsageLog.Feature.
    /// Keep these in sync with any UI display labels in AiUsageReport.
    /// </summary>
    public static class AiFeatures
    {
        public const string PhotoQuote       = "PhotoQuote";
        public const string HelpChat         = "HelpChat";
        public const string ReceiptScan      = "ReceiptScan";
        public const string AccountSuggest   = "AccountSuggest";
        public const string ArFollowUp       = "ArFollowUp";
        public const string FinancialSummary = "FinancialSummary";
        public const string CashFlowForecast        = "CashFlowForecast";
        public const string AnomalyDetection        = "AnomalyDetection";
        public const string BankRecAutoMatch        = "BankRecAutoMatch";
        public const string LatePaymentPrediction   = "LatePaymentPrediction";
        public const string FinancialQuery          = "FinancialQuery";
        public const string RecurringBillDetection  = "RecurringBillDetection";
    }

    public static class Legal
    {
        /// <summary>
        /// Bump this string whenever the Terms of Service content changes.
        /// The new value will be recorded on all future acceptances.
        /// Format: YYYY-MM-DD of the effective date.
        /// </summary>
        public const string CurrentTosVersion = "2026-04-09";
    }

    public static class GuidedActivation
    {
        public const string QuoteFirstPath = "quote_first";
        public const string JobFirstPath = "job_first";

        public const string QueryKey = "guidedActivation";
        public const string HighlightJobIdKey = "highlightJobId";
        public const string QuoteCreatedStep = "quote_created";
        public const string JobCreatedStep = "job_created";
        public const string BoardIntroStep = "board_intro";
        public const string BoardReadyForInvoiceStep = "board_ready_for_invoice";
        public const string InvoiceCreatedStep = "invoice_created";
    }

    public static class PowderInsights
    {
        public const int Layer3MinJobs = 150;  // Minimum jobs with actual powder data before Layer 3 predictive features unlock
        public const int Layer2MinJobs = 10;   // Minimum for efficiency trending to be meaningful
    }

    /// <summary>
    /// String codes stored in the JobStatusLookup and QuoteStatusLookup tables.
    /// Using constants here means a DB code rename only requires one code change,
    /// not a grep-and-replace across every controller.
    /// </summary>
    public static class StatusCodes
    {
        public static class Job
        {
            public const string Pending          = "PENDING";
            public const string Quoted           = "QUOTED";
            public const string Approved         = "APPROVED";
            public const string InPreparation    = "IN_PREPARATION";
            public const string Sandblasting     = "SANDBLASTING";
            public const string MaskingTaping    = "MASKING_TAPING";
            public const string Cleaning         = "CLEANING";
            public const string InOven           = "IN_OVEN";
            public const string Coating          = "COATING";
            public const string Curing           = "CURING";
            public const string QualityCheck     = "QUALITY_CHECK";
            public const string Completed        = "COMPLETED";
            public const string ReadyForPickup   = "READY_FOR_PICKUP";
            public const string Delivered        = "DELIVERED";
            public const string OnHold           = "ON_HOLD";
            public const string Cancelled        = "CANCELLED";
        }

        public static class Quote
        {
            public const string Draft     = "DRAFT";
            public const string Sent      = "SENT";
            public const string Approved  = "APPROVED";
            public const string Rejected  = "REJECTED";
            public const string Converted = "CONVERTED";
            public const string Expired   = "EXPIRED";
        }
    }
}
