import {scopedEndpoint} from '@/shared/services/httpClient';
import type {Endpoint, Scope} from '@/shared/services/httpClient';
import type {
  ActivityEvent,
  DashboardBriefing,
  Granularity,
  HourCell,
  Kpi,
  PeriodPoint,
  RewardUsagePoint,
  StoreComparison,
  TimePoint,
} from '@/features/dashboard/types/dashboard';

/**
 * Every URL the dashboard knows, and the only place it knows them.
 *
 * This is the file a backend integration edits. Each method returns a typed
 * Endpoint rather than data, so the transport stays declarative: useResource
 * keys off the URL, which is what makes a store or range change refetch while
 * an unrelated re-render does not.
 *
 * A repository never interprets. No formatting, no filtering, no defaults —
 * those are the service's job, and keeping them out of here is what allows a
 * REST backend to be swapped for GraphQL by changing this file alone.
 */
export const dashboardRepository = {
  kpis: (scope: Scope): Endpoint<Kpi[]> =>
    scopedEndpoint('/api/dashboard/kpis', scope),

  briefing: (scope: Scope): Endpoint<DashboardBriefing> =>
    scopedEndpoint('/api/dashboard/briefing', scope),

  timeseries: (scope: Scope): Endpoint<TimePoint[]> =>
    scopedEndpoint('/api/dashboard/timeseries', scope),

  peakHours: (scope: Scope): Endpoint<HourCell[]> =>
    scopedEndpoint('/api/dashboard/peak-hours', scope),

  activity: (scope: Scope): Endpoint<ActivityEvent[]> =>
    scopedEndpoint('/api/dashboard/activity', scope),

  storeComparison: (scope: Scope): Endpoint<StoreComparison[]> =>
    scopedEndpoint('/api/dashboard/store-comparison', scope),

  rewardUsage: (scope: Scope): Endpoint<RewardUsagePoint[]> =>
    scopedEndpoint('/api/dashboard/reward-usage', scope),

  performance: (scope: Scope, granularity: Granularity): Endpoint<PeriodPoint[]> =>
    scopedEndpoint('/api/dashboard/performance', scope, {granularity}),
};
