import type { BookingListFilter } from "@/services/bookings.service";
import type { RuleEngineListParams } from "@/services/ruleEngine/ruleEngine.service";
import type { TrainScheduleFilters } from "@/types/trainScheduling";
import type { RuleEngineResourceSlug } from "@/types/rule-engine";

export const QUERY_KEYS = {
  USERS: {
    ROOT: ["users"] as const,
    ADD: ["users", "add"] as const,
  },

  FILES: {
    ROOT: ["file-upload-settings"] as const,
    list: () => ["file-upload-settings", "list"] as const,
    byId: (id: string) => ["file-upload-settings", "detail", id] as const,
    byCode: (code: string) => ["file-upload-settings", "by-code", code] as const,
  },

  DROPDOWN_SETTINGS: {
    ROOT: ["dropdown-settings"] as const,
    list: () => ["dropdown-settings", "list"] as const,
    byId: (id: string) => ["dropdown-settings", "detail", id] as const,
    byCode: (code: string) => ["dropdown-settings", "by-code", code] as const,
  },

  CUSTOMERS: {
    ROOT: ["customers"] as const,
    list: () => ["customers", "list"] as const,
    byId: (id: string) => ["customers", "detail", id] as const,
  },

  BOOKINGS: {
    ROOT: ["bookings"] as const,
    list: (filter?: BookingListFilter) =>
      ["bookings", "list", filter ?? {}] as const,
    listSummary: (filter?: BookingListFilter) =>
      ["bookings", "list-summary", filter ?? {}] as const,
    byId: (id: string) => ["bookings", "detail", id] as const,
  },

  TRAIN_SCHEDULING: {
    ROOT: ["train-scheduling"] as const,
    eligible: (filters?: TrainScheduleFilters) =>
      ["train-scheduling", "eligible-bookings", filters ?? {}] as const,
    locomotives: () => ["train-scheduling", "locomotives"] as const,
    stations: () => ["train-scheduling", "stations"] as const,
    schedules: () => ["train-scheduling", "schedules"] as const,
    scheduleById: (id: string) => ["train-scheduling", "schedule", id] as const,
  },

  RULE_ENGINE: {
    ROOT: ["rule-engine"] as const,
    list: (resource: RuleEngineResourceSlug | string, params?: RuleEngineListParams) =>
      ["rule-engine", "list", resource, params ?? {}] as const,
    detail: (resource: RuleEngineResourceSlug | string, id: string) =>
      ["rule-engine", "detail", resource, id] as const,
    chain: ["rule-engine", "approval-rules", "chain"] as const,
    selectOptions: (
      resource: RuleEngineResourceSlug | string,
      params?: Record<string, unknown>,
    ) => ["rule-engine", "select-options", resource, params ?? {}] as const,
  },
} as const;
