/**
 * User Management Constants
 *
 * Centralized configuration values, magic numbers, and string constants
 * for the user management feature.
 *
 * @module constants/user-management
 */

// ============================================
// VALIDATION CONSTANTS
// ============================================

export const VALIDATION = {
  /** Note content validation */
  NOTE: {
    MIN_LENGTH: 5,
    MAX_LENGTH: 5000,
  },

  /** Suspension reason validation */
  SUSPENSION: {
    REASON_MIN_LENGTH: 5,
  },

  /** Billing email validation */
  BILLING: {
    SUBJECT_MIN_LENGTH: 5,
    SUBJECT_MAX_LENGTH: 200,
    CONTENT_MIN_LENGTH: 10,
    CONTENT_MAX_LENGTH: 10000,
  },

  /** Pagination limits */
  PAGINATION: {
    DEFAULT_LIMIT: 50,
    MAX_LIMIT: 100,
    MIN_PAGE: 1,
  },
} as const;

// ============================================
// QUERY LIMITS
// ============================================

export const QUERY_LIMITS = {
  /** Maximum login history records to fetch */
  LOGIN_HISTORY: 50,

  /** Maximum admin notes to fetch */
  ADMIN_NOTES: 50,

  /** Maximum billing emails to fetch */
  BILLING_EMAILS: 50,

  /** Maximum audit logs to fetch */
  AUDIT_LOGS: 100,

  /** Maximum subscriptions to fetch */
  SUBSCRIPTIONS: 10,
} as const;

// ============================================
// TIME PERIODS
// ============================================

export const TIME_PERIODS = {
  /** Time window for "new this week" calculation */
  ONE_WEEK_MS: 7 * 24 * 60 * 60 * 1000,

  /** Auto-refresh interval (30 seconds) */
  AUTO_REFRESH_INTERVAL_MS: 30 * 1000,

  /** Login history retention period */
  LOGIN_HISTORY_RETENTION_DAYS: 90,

  /** Clipboard copy feedback duration */
  CLIPBOARD_FEEDBACK_MS: 2000,
} as const;

// ============================================
// ACCOUNT STATUS
// ============================================

export const ACCOUNT_STATUS = {
  ACTIVE: "active",
  SUSPENDED: "suspended",
  LOCKED: "locked",
  INACTIVE: "inactive",
} as const;

export const STATUS_COLORS = {
  active: {
    bg: "bg-green-50",
    text: "text-green-700",
    border: "border-green-200",
    icon: "🟢",
  },
  suspended: {
    bg: "bg-orange-50",
    text: "text-orange-700",
    border: "border-orange-200",
    icon: "🟠",
  },
  locked: {
    bg: "bg-red-50",
    text: "text-red-700",
    border: "border-red-200",
    icon: "🔴",
  },
  inactive: {
    bg: "bg-gray-50",
    text: "text-gray-700",
    border: "border-gray-200",
    icon: "⚪",
  },
} as const;

// ============================================
// NOTE CATEGORIES
// ============================================

export const NOTE_CATEGORIES = {
  GENERAL: {
    value: "GENERAL",
    label: "General",
    color: "blue",
    icon: "📝",
  },
  BILLING: {
    value: "BILLING",
    label: "Billing",
    color: "green",
    icon: "💰",
  },
  SUPPORT: {
    value: "SUPPORT",
    label: "Support",
    color: "purple",
    icon: "🆘",
  },
  COMPLIANCE: {
    value: "COMPLIANCE",
    label: "Compliance",
    color: "red",
    icon: "⚖️",
  },
  TECHNICAL: {
    value: "TECHNICAL",
    label: "Technical",
    color: "indigo",
    icon: "⚙️",
  },
  SALES: {
    value: "SALES",
    label: "Sales",
    color: "pink",
    icon: "💼",
  },
} as const;

// ============================================
// EMAIL STATUS
// ============================================

export const EMAIL_STATUS = {
  DRAFT: { value: "DRAFT", label: "Draft", color: "gray" },
  SENT: { value: "SENT", label: "Sent", color: "blue" },
  OPENED: { value: "OPENED", label: "Opened", color: "purple" },
  PAID: { value: "PAID", label: "Paid", color: "green" },
  OVERDUE: { value: "OVERDUE", label: "Overdue", color: "red" },
  CANCELLED: { value: "CANCELLED", label: "Cancelled", color: "gray" },
} as const;

// ============================================
// USER ROLES
// ============================================

export const USER_ROLES = {
  CUSTOMER: { value: "CUSTOMER", label: "Customer", color: "blue" },
  STAFF: { value: "STAFF", label: "Staff", color: "purple" },
  ADMIN: { value: "ADMIN", label: "Admin", color: "red" },
  SUPER_ADMIN: { value: "SUPER_ADMIN", label: "Super Admin", color: "orange" },
} as const;

// ============================================
// GEOLOCATION
// ============================================

export const GEOLOCATION = {
  /** GCC Countries (our primary target market) */
  GCC_COUNTRIES: ["Qatar", "UAE", "Saudi Arabia", "Kuwait", "Bahrain", "Oman"],

  /** Private IP ranges */
  PRIVATE_IP_PREFIXES: ["127.", "192.168.", "10.", "169.254."],

  /** Default location for private IPs */
  DEFAULT_LOCATION: {
    country: "Local Development",
    countryCode: "XX",
    city: "localhost",
    region: "N/A",
    latitude: 0,
    longitude: 0,
    timezone: "UTC",
  },

  /** API timeout for external geolocation service */
  API_TIMEOUT_MS: 5000,

  /** Batch size for geolocation lookups */
  BATCH_SIZE: 10,

  /** Rate limit delay between batches */
  RATE_LIMIT_DELAY_MS: 100,
} as const;

// ============================================
// API ENDPOINTS
// ============================================

export const API_ENDPOINTS = {
  /** List users with filters */
  LIST_USERS: "/api/staff/dashboard/users",

  /** Get user details */
  USER_DETAILS: "/api/staff/users/:id",

  /** Update account status */
  UPDATE_STATUS: "/api/staff/users/:id/status",

  /** Admin notes */
  ADMIN_NOTES: "/api/staff/users/:id/notes",

  /** Billing emails */
  BILLING_EMAIL: "/api/staff/users/:id/billing/email",

  /** Geography analytics */
  GEOGRAPHY_ANALYTICS: "/api/staff/analytics/geography",
} as const;

// ============================================
// UI CONSTANTS
// ============================================

export const UI = {
  /** Table page size options */
  PAGE_SIZES: [20, 50, 100],

  /** Default table page size */
  DEFAULT_PAGE_SIZE: 50,

  /** Max visible pagination buttons */
  MAX_PAGINATION_BUTTONS: 5,

  /** CSV export filename pattern */
  CSV_FILENAME: "users-export-{date}.csv",

  /** Modal max width */
  MODAL_MAX_WIDTH: "4xl",

  /** Auto-refresh interval label */
  AUTO_REFRESH_LABEL: "Auto-refresh (30s)",
} as const;

// ============================================
// SORT OPTIONS
// ============================================

export const SORT_OPTIONS = [
  { value: "createdAt", label: "Registration Date", default: true },
  { value: "lastLoginAt", label: "Last Login" },
  { value: "loginCount", label: "Login Count" },
  { value: "email", label: "Email" },
  { value: "name", label: "Name" },
] as const;

// ============================================
// FILTER OPTIONS
// ============================================

export const STATUS_FILTER_OPTIONS = [
  { value: "all", label: "All Status" },
  { value: "active", label: "Active" },
  { value: "suspended", label: "Suspended" },
  { value: "locked", label: "Locked" },
] as const;

export const ROLE_FILTER_OPTIONS = [
  { value: "all", label: "All Roles" },
  { value: "CUSTOMER", label: "Customers" },
  { value: "STAFF", label: "Staff" },
  { value: "ADMIN", label: "Admins" },
] as const;

// ============================================
// ERROR MESSAGES
// ============================================

export const ERROR_MESSAGES = {
  UNAUTHORIZED: "You must be logged in to access this resource",
  FORBIDDEN: "You do not have permission to perform this action",
  USER_NOT_FOUND: "User not found",
  CANNOT_SUSPEND_ADMIN:
    "Cannot suspend administrator accounts for security reasons",
  REASON_REQUIRED: "Reason is required for this action",
  REASON_TOO_SHORT: "Reason must be at least 5 characters",
  CONTENT_TOO_SHORT: "Content is too short",
  CONTENT_TOO_LONG: "Content is too long",
  INVALID_CATEGORY: "Invalid category selected",
  INVALID_ACTION: "Invalid action specified",
  NETWORK_ERROR: "Network error. Please try again.",
  SERVER_ERROR: "Server error. Please contact support.",
} as const;

// ============================================
// SUCCESS MESSAGES
// ============================================

export const SUCCESS_MESSAGES = {
  ACCOUNT_SUSPENDED: "Account suspended successfully",
  ACCOUNT_ACTIVATED: "Account activated successfully",
  NOTE_ADDED: "Admin note added successfully",
  EMAIL_SENT: "Billing email sent successfully",
  DATA_EXPORTED: "Data exported successfully",
  DATA_REFRESHED: "Data refreshed successfully",
} as const;

// ============================================
// FEATURE FLAGS
// ============================================

export const FEATURE_FLAGS = {
  /** Enable CSV export feature */
  ENABLE_CSV_EXPORT: true,

  /** Enable map view */
  ENABLE_MAP_VIEW: true,

  /** Enable auto-refresh */
  ENABLE_AUTO_REFRESH: true,

  /** Enable billing emails */
  ENABLE_BILLING_EMAILS: true,

  /** Enable admin notes */
  ENABLE_ADMIN_NOTES: true,

  /** Use dual-database sync */
  USE_DUAL_DATABASE: true,

  /** Use geolocation API fallback */
  USE_GEOLOCATION_API_FALLBACK: true,
} as const;

// ============================================
// PERMISSIONS
// ============================================

export const PERMISSIONS = {
  /** Who can view user list */
  VIEW_USERS: ["STAFF", "ADMIN", "SUPER_ADMIN"],

  /** Who can add admin notes */
  ADD_NOTES: ["STAFF", "ADMIN", "SUPER_ADMIN"],

  /** Who can send billing emails */
  SEND_BILLING: ["STAFF", "ADMIN", "SUPER_ADMIN"],

  /** Who can suspend/activate accounts */
  MODIFY_STATUS: ["ADMIN", "SUPER_ADMIN"],

  /** Who can export CSV */
  EXPORT_DATA: ["ADMIN", "SUPER_ADMIN"],
} as const;

// ============================================
// TABLE COLUMNS
// ============================================

export const TABLE_COLUMNS = {
  USER: { id: "user", label: "User", width: "250px", sortable: true },
  ROLE_STATUS: {
    id: "role",
    label: "Role/Status",
    width: "150px",
    sortable: false,
  },
  COMPANY: {
    id: "company",
    label: "Company/Industry",
    width: "200px",
    sortable: false,
  },
  LOCATION: {
    id: "location",
    label: "Location/IP",
    width: "200px",
    sortable: false,
  },
  ACTIVITY: {
    id: "activity",
    label: "Activity",
    width: "150px",
    sortable: true,
  },
  LAST_LOGIN: {
    id: "lastLogin",
    label: "Last Login",
    width: "150px",
    sortable: true,
  },
} as const;
