import { BaseApiService } from '@/services/api/base';
import { BaseApiResponse } from '@/types/api/api-general';
import { Dashboard, DashboardFilter } from '@/types/api/dashboard/dashboard';

class DashboardService extends BaseApiService<Dashboard, unknown, unknown> {
  constructor(basePath: string) {
    super(basePath);
  }

  /**
   * Fetch dashboard production data
   * @param endpoint - The endpoint URL with query parameters
   * @returns Promise with BaseApiResponse containing DashboardProduction
   */
  async getDashboardProductionFetcher(
    params: DashboardFilter
  ): Promise<BaseApiResponse<Dashboard> | undefined> {
    return await this.customRequest<BaseApiResponse<Dashboard>>('', {
      method: 'GET',
      params: {
        start_date: params.start_date || undefined,
        end_date: params.end_date || undefined,
        analysis_mode: params.analysis_mode || undefined,
        location_ids: params.location_ids.length
          ? params.location_ids.toString()
          : undefined,
        flock_ids: params.flock_ids.length
          ? params.flock_ids.toString()
          : undefined,
        kandang_ids: params.kandang_ids.length
          ? params.kandang_ids.toString()
          : undefined,
        comparison_type: params.comparison_type || undefined,
      },
    });
  }
}

export const DashboardApi = new DashboardService('/dashboards');
