/**
 * Dashboard API Client
 */

import { get } from '../../src/lib/api/client';

export interface DashboardKPIs {
  bookingsThisMonth: number;
  totalTEUs: number;
  estimatedRevenue: number;
  pendingConfirmations: number;
  bookingsThisMonthChange: number;
  totalTEUsChange: number;
  estimatedRevenueChange: number;
  pendingConfirmationsChange: number;
}

export interface BookingsChartData {
  labels: string[];
  data: number[];
}

export interface TopTradeLane {
  route: string;
  originPort: string;
  destinationPort: string;
  bookingCount: number;
  totalTEUs: number;
  avgPrice: number;
}

export interface DashboardAlert {
  id: string;
  type: 'delay' | 'confirmation' | 'document' | 'payment' | 'info';
  severity: 'low' | 'medium' | 'high' | 'critical';
  title: string;
  message: string;
  bookingId?: string;
  bookingNumber?: string;
  createdAt: string;
  isRead: boolean;
}

export const dashboardApi = {
  /**
   * Get dashboard KPIs
   */
  async getKPIs(): Promise<DashboardKPIs> {
    return get<DashboardKPIs>('/api/v1/dashboard/kpis');
  },

  /**
   * Get bookings chart data
   */
  async getBookingsChart(): Promise<BookingsChartData> {
    return get<BookingsChartData>('/api/v1/dashboard/bookings-chart');
  },

  /**
   * Get top trade lanes
   */
  async getTopTradeLanes(): Promise<TopTradeLane[]> {
    return get<TopTradeLane[]>('/api/v1/dashboard/top-trade-lanes');
  },

  /**
   * Get dashboard alerts
   */
  async getAlerts(): Promise<DashboardAlert[]> {
    return get<DashboardAlert[]>('/api/v1/dashboard/alerts');
  },
};
