// SCB Admin API Service
import { apiClient } from './client';
import type { SCBOverviewDashboard, FIManagementDashboard, CorridorPolicyDashboard } from '@/types/dashboard';

class SCBAdminAPI {
  // SCB Overview
  async getSCBOverview(scbId: string): Promise<SCBOverviewDashboard> {
    try {
      return await apiClient.get<SCBOverviewDashboard>(`/api/admin/scb/dashboard/overview`);
    } catch (error: any) {
      if (error?.code === 'ERR_NETWORK' || error?.isNetworkError || error?.message?.includes('Network') || error?.message?.includes('API unavailable')) {
        console.warn('API not available, using mock data');
        return {} as SCBOverviewDashboard;
      }
      throw error;
    }
  }

  // FI Management
  async getFIManagementDashboard(scbId: string): Promise<FIManagementDashboard> {
    try {
      return await apiClient.get<FIManagementDashboard>(`/api/admin/scb/fi`);
    } catch (error: any) {
      if (error?.code === 'ERR_NETWORK' || error?.isNetworkError || error?.message?.includes('Network') || error?.message?.includes('API unavailable')) {
        console.warn('API not available, using mock data');
        return {} as FIManagementDashboard;
      }
      throw error;
    }
  }

  // Corridor & FX Policy
  async getCorridorPolicyDashboard(scbId: string): Promise<CorridorPolicyDashboard> {
    try {
      return await apiClient.get<CorridorPolicyDashboard>(`/api/admin/scb/corridors`);
    } catch (error: any) {
      if (error?.code === 'ERR_NETWORK' || error?.isNetworkError || error?.message?.includes('Network') || error?.message?.includes('API unavailable')) {
        console.warn('API not available, using mock data');
        return {} as CorridorPolicyDashboard;
      }
      throw error;
    }
  }
}

export const scbAdminApi = new SCBAdminAPI();
