// API Configuration Types
interface ApiConfig {
  BASE_URL: string;
  ENDPOINTS: Record<string, string>;
  DEFAULT_HEADERS: Record<string, string>;
  TIMEOUT: number;
}

const API_CONFIG: ApiConfig = {
  // Use same-origin relative URLs in production so the app works on any domain.
  BASE_URL: import.meta.env.VITE_FRAPPE_BASE_URL || '',
  
  // API Endpoints
  ENDPOINTS: {
    // User Management
    USER_DETAILS: '/api/method/asset_lite.api.custom_api.get_user_details',
    
    // Data Management
    DOCTYPE_RECORDS: '/api/method/asset_lite.api.custom_api.get_doctype_records',
    
    // Dashboard
    DASHBOARD_STATS: '/api/method/asset_lite.api.custom_api.get_dashboard_stats',
    DASHBOARD_NUMBER_CARDS: '/api/method/asset_lite.api.dashboard_api.get_number_cards',
    DASHBOARD_WORK_ORDER_METRICS: '/api/method/asset_lite.api.dashboard_api.get_dashboard_work_order_metrics',
    DASHBOARD_ASSET_DEVICE_STATUS: '/api/method/asset_lite.api.dashboard_api.get_asset_device_status_summary',
    DASHBOARD_LIST_CHARTS: '/api/method/asset_lite.api.dashboard_api.list_dashboard_charts',
    DASHBOARD_CHART_DATA: '/api/method/asset_lite.api.dashboard_api.get_dashboard_chart_data',
    DASHBOARD_REPAIR_COST: '/api/method/asset_lite.api.dashboard_api.get_repair_cost_by_item',
    
    // KYC Management
    KYC_DETAILS: '/api/method/asset_lite.api.custom_api.get_kyc_details',
    
    // Asset Management
    GET_ASSETS: '/api/method/asset_lite.api.asset_api.get_assets',
    GET_ASSET_DETAILS: '/api/method/asset_lite.api.asset_api.get_asset_details',
    CREATE_ASSET: '/api/method/asset_lite.api.asset_api.create_asset',
    UPDATE_ASSET: '/api/method/asset_lite.api.asset_api.update_asset',
    DELETE_ASSET: '/api/method/asset_lite.api.asset_api.delete_asset',
    GET_ASSET_FILTERS: '/api/method/asset_lite.api.asset_api.get_asset_filters',
    GET_ASSET_STATS: '/api/method/asset_lite.api.asset_api.get_asset_stats',
    SEARCH_ASSETS: '/api/method/asset_lite.api.asset_api.search_assets',
    SUBMIT_ASSET: '/api/method/asset_lite.api.asset_api.submit_asset',
    CANCEL_ASSET: '/api/method/asset_lite.api.asset_api.cancel_asset',
    
    // Work Order Management
    GET_WORK_ORDERS: '/api/method/asset_lite.api.work_order_api.get_work_orders',
    GET_WORK_ORDER_DETAILS: '/api/method/asset_lite.api.work_order_api.get_work_order_details',
    CREATE_WORK_ORDER: '/api/method/asset_lite.api.work_order_api.create_work_order',
    UPDATE_WORK_ORDER: '/api/method/asset_lite.api.work_order_api.update_work_order',
    DELETE_WORK_ORDER: '/api/method/asset_lite.api.work_order_api.delete_work_order',
    UPDATE_WORK_ORDER_STATUS: '/api/method/asset_lite.api.work_order_api.update_work_order_status',
    
    // Asset Maintenance Management
    GET_ASSET_MAINTENANCE_LOGS: '/api/method/asset_lite.api.asset_maintenance_api.get_asset_maintenance_logs',
    GET_ASSET_MAINTENANCE_LOG_DETAILS: '/api/method/asset_lite.api.asset_maintenance_api.get_asset_maintenance_log_details',
    CREATE_ASSET_MAINTENANCE_LOG: '/api/method/asset_lite.api.asset_maintenance_api.create_asset_maintenance_log',
    UPDATE_ASSET_MAINTENANCE_LOG: '/api/method/asset_lite.api.asset_maintenance_api.update_asset_maintenance_log',
    DELETE_ASSET_MAINTENANCE_LOG: '/api/method/asset_lite.api.asset_maintenance_api.delete_asset_maintenance_log',
    UPDATE_MAINTENANCE_STATUS: '/api/method/asset_lite.api.asset_maintenance_api.update_maintenance_status',
    GET_MAINTENANCE_LOGS_BY_ASSET: '/api/method/asset_lite.api.asset_maintenance_api.get_maintenance_logs_by_asset',
    GET_OVERDUE_MAINTENANCE_LOGS: '/api/method/asset_lite.api.asset_maintenance_api.get_overdue_maintenance_logs',
    
    // PPM (Asset Maintenance) Management
    GET_ASSET_MAINTENANCES: '/api/method/asset_lite.api.ppm_api.get_asset_maintenances',
    GET_ASSET_MAINTENANCE_DETAILS: '/api/method/asset_lite.api.ppm_api.get_asset_maintenance_details',
    CREATE_ASSET_MAINTENANCE: '/api/method/asset_lite.api.ppm_api.create_asset_maintenance',
    UPDATE_ASSET_MAINTENANCE: '/api/method/asset_lite.api.ppm_api.update_asset_maintenance',
    DELETE_ASSET_MAINTENANCE: '/api/method/asset_lite.api.ppm_api.delete_asset_maintenance',
    GET_MAINTENANCE_TASKS: '/api/method/asset_lite.api.ppm_api.get_maintenance_tasks',
    GET_SERVICE_COVERAGE: '/api/method/asset_lite.api.ppm_api.get_service_coverage',
    GET_MAINTENANCES_BY_ASSET: '/api/method/asset_lite.api.ppm_api.get_maintenances_by_asset',
    GET_ACTIVE_SERVICE_CONTRACTS: '/api/method/asset_lite.api.ppm_api.get_active_service_contracts',
    
    // Authentication
    LOGIN: '/api/method/login',
    LOGOUT: '/api/method/logout',
    CSRF_TOKEN: '/api/method/asset_lite.api.custom_api.get_user_details',
    RESET_PASSWORD: '/api/method/frappe.core.doctype.user.user.reset_password',
    
    // File Upload
    UPLOAD_FILE: '/api/method/upload_file',

    // User Permission Management - Generic (only these are needed!)
    GET_USER_PERMISSIONS: '/api/method/asset_lite.api.userperm_api.get_user_permissions',
    GET_PERMISSION_FILTERS: '/api/method/asset_lite.api.userperm_api.get_permission_filters',
    GET_ALLOWED_VALUES: '/api/method/asset_lite.api.userperm_api.get_allowed_values',
    CHECK_DOCUMENT_ACCESS: '/api/method/asset_lite.api.userperm_api.check_document_access',
    GET_CONFIGURED_DOCTYPES: '/api/method/asset_lite.api.userperm_api.get_configured_doctypes',
    GET_USER_DEFAULTS: '/api/method/asset_lite.api.userperm_api.get_user_defaults',

  },
  
  // Request Configuration
  DEFAULT_HEADERS: {
    'Content-Type': 'application/json',
    'Accept': 'application/json'
  },
  
  // Timeout settings - increased for debugging
  TIMEOUT: parseInt(import.meta.env.VITE_API_TIMEOUT || '60000'),
};

export default API_CONFIG;
