"use client";

import { 
  fetchAllShopsAction, 
  findTruckLaneByShopIdAction,
  updateTruckLaneAction,
  updateLaneLogisticAction,
  deleteTruckLaneAction,
  createTruckAction,
  findAllUniqueTruckLaneCombinationsAction,
  findAllForRouteBoardAction,
  exportRouteLanesExcelAction,
  exportRouteReportExcelAction,
  exportTruckLaneVersionReportExcelAction,
  importRouteLanesExcelAction,
  parseRouteLanesExcelAction,
  type ParseRouteLanesExcelResponse,
  type RouteLaneImportPreviewRow,
  findAllShopsByTruckLanceCodeAndRemarkAction,
  findAllShopsByTruckLanceCodeAction,
  createTruckWithoutShopAction,
  updateTruckShopDetailsAction,
  findAllUniqueShopNamesAndCodesFromTrucksAction,
  findAllUniqueRemarksFromTrucksAction,
  findAllUniqueShopCodesFromTrucksAction,
  findAllUniqueShopNamesFromTrucksAction,
  createTruckLaneSnapshotAction,
  listTruckLaneVersionsAction,
  getTruckLaneVersionLinesAction,
  diffTruckLaneVersionsAction,
  restoreTruckLaneVersionAction,
  updateTruckLaneVersionNoteAction,
  createTruckLaneScheduleAction,
  planTruckLaneScheduleFromRouteExcelAction,
  listTruckLaneSchedulesAction,
  getTruckLaneScheduleAction,
  pendingTruckLaneScheduleShopIdsAction,
  cancelTruckLaneScheduleAction,
  applyNowTruckLaneScheduleAction,
  retryFailedTruckLaneScheduleAction,
  ignoreTruckLaneScheduleAction,
  type RetryFailedTruckLaneScheduleRequest,
  parseTruckLaneScheduleExcelAction,
  importTruckLaneScheduleExcelAction,
  type CreateTruckLaneSnapshotRequest,
  type CreateTruckLaneScheduleRequest,
  type TruckLaneScheduleResponse,
  type TruckLaneScheduleLineRequest,
  type RouteExcelSchedulePlanPreviewRow,
  type RouteExcelSchedulePlanError,
  type RouteExcelSchedulePlanResponse,
  type RouteExcelSchedulePlanCounts,
  type TruckLaneMoveTargetRequest,
  type PendingTruckRowIdsResponse,
  type ParseTruckLaneScheduleExcelResponse,
  type UpdateTruckLaneVersionNoteRequest,
  type TruckLaneVersionResponse,
  type TruckLaneVersionLineResponse,
  type TruckLaneVersionDiffResponse,
  findAllByTruckLanceCodeAndDeletedFalseAction,
  findAllByTruckLanceCodeAndRemarkAndDeletedFalseAction,
  type SaveTruckLane,
  type UpdateLaneLogisticRequest,
  type DeleteTruckLane,
  type SaveTruckRequest,
  type UpdateTruckShopDetailsRequest,
  type CreateTruckWithoutShopRequest,
  type MessageResponse
} from "./actions";

export const fetchAllShopsClient = async (params?: Record<string, string | number | null>) => {
  return await fetchAllShopsAction(params);
};

export const findTruckLaneByShopIdClient = async (shopId: number | string) => {
  return await findTruckLaneByShopIdAction(shopId);
};

export const updateTruckLaneClient = async (data: SaveTruckLane): Promise<MessageResponse> => {
  return await updateTruckLaneAction(data);
};

export const updateLaneLogisticClient = async (
  data: UpdateLaneLogisticRequest,
): Promise<MessageResponse> => {
  return await updateLaneLogisticAction(data);
};

export const deleteTruckLaneClient = async (data: DeleteTruckLane): Promise<MessageResponse> => {
  return await deleteTruckLaneAction(data);
};

export const createTruckClient = async (data: SaveTruckRequest): Promise<MessageResponse> => {
  return await createTruckAction(data);
};

export const findAllUniqueTruckLaneCombinationsClient = async () => {
  return await findAllUniqueTruckLaneCombinationsAction();
};

export const findAllForRouteBoardClient = async () => {
  return await findAllForRouteBoardAction();
};

export const exportRouteLanesExcelClient = async (laneIds: string[]) => {
  return await exportRouteLanesExcelAction(laneIds);
};

export const exportRouteReportExcelClient = async (laneIds: string[]) => {
  return await exportRouteReportExcelAction(laneIds);
};

export const exportTruckLaneVersionReportExcelClient = async (
  fromVersionId: number,
  toVersionId: number,
) => {
  return await exportTruckLaneVersionReportExcelAction(fromVersionId, toVersionId);
};

export const importRouteLanesExcelClient = async (formData: FormData) => {
  return await importRouteLanesExcelAction(formData);
};

export const parseRouteLanesExcelClient = async (formData: FormData) => {
  return await parseRouteLanesExcelAction(formData);
};

export type { ParseRouteLanesExcelResponse, RouteLaneImportPreviewRow };

export const findAllShopsByTruckLanceCodeAndRemarkClient = async (truckLanceCode: string, remark: string) => {
  return await findAllShopsByTruckLanceCodeAndRemarkAction(truckLanceCode, remark);
};

export const findAllShopsByTruckLanceCodeClient = async (truckLanceCode: string) => {
  return await findAllShopsByTruckLanceCodeAction(truckLanceCode);
};

export const findAllByTruckLanceCodeAndDeletedFalseClient = async (truckLanceCode: string) => {
  return await findAllByTruckLanceCodeAndDeletedFalseAction(truckLanceCode);
};

export const findAllByTruckLanceCodeAndRemarkAndDeletedFalseClient = async (
  truckLanceCode: string,
  remark: string | null | undefined,
) => {
  return await findAllByTruckLanceCodeAndRemarkAndDeletedFalseAction(truckLanceCode, remark);
};

export const updateTruckShopDetailsClient = async (data: UpdateTruckShopDetailsRequest): Promise<MessageResponse> => {
  return await updateTruckShopDetailsAction(data);
};

export const createTruckWithoutShopClient = async (data: CreateTruckWithoutShopRequest): Promise<MessageResponse> => {
  return await createTruckWithoutShopAction(data);
};

export const findAllUniqueShopNamesAndCodesFromTrucksClient = async () => {
  return await findAllUniqueShopNamesAndCodesFromTrucksAction();
};

export const findAllUniqueRemarksFromTrucksClient = async () => {
  return await findAllUniqueRemarksFromTrucksAction();
};

export const findAllUniqueShopCodesFromTrucksClient = async () => {
  return await findAllUniqueShopCodesFromTrucksAction();
};

export const findAllUniqueShopNamesFromTrucksClient = async () => {
  return await findAllUniqueShopNamesFromTrucksAction();
};

export const createTruckLaneSnapshotClient = async (
  data: CreateTruckLaneSnapshotRequest,
): Promise<TruckLaneVersionResponse> => {
  return await createTruckLaneSnapshotAction(data);
};

export const listTruckLaneVersionsClient = async (
  truckLanceCode?: string | null,
): Promise<TruckLaneVersionResponse[]> => {
  return await listTruckLaneVersionsAction(truckLanceCode);
};

export const getTruckLaneVersionLinesClient = async (
  versionId: number,
): Promise<TruckLaneVersionLineResponse[]> => {
  return await getTruckLaneVersionLinesAction(versionId);
};

export const diffTruckLaneVersionsClient = async (
  fromVersionId: number,
  toVersionId: number,
): Promise<TruckLaneVersionDiffResponse> => {
  return await diffTruckLaneVersionsAction(fromVersionId, toVersionId);
};

export const restoreTruckLaneVersionClient = async (versionId: number): Promise<MessageResponse> => {
  return await restoreTruckLaneVersionAction(versionId);
};

export const updateTruckLaneVersionNoteClient = async (
  versionId: number,
  data: UpdateTruckLaneVersionNoteRequest,
): Promise<TruckLaneVersionResponse> => {
  return await updateTruckLaneVersionNoteAction(versionId, data);
};

export const planTruckLaneScheduleFromRouteExcelClient = async (
  formData: FormData,
): Promise<RouteExcelSchedulePlanResponse> => {
  return await planTruckLaneScheduleFromRouteExcelAction(formData);
};

export const createTruckLaneScheduleClient = async (
  data: CreateTruckLaneScheduleRequest,
): Promise<TruckLaneScheduleResponse> => {
  return await createTruckLaneScheduleAction(data);
};

export const listTruckLaneSchedulesClient = async (
  status?: string[],
  limit: number = 200,
): Promise<TruckLaneScheduleResponse[]> => {
  return await listTruckLaneSchedulesAction(status, limit);
};

export const getTruckLaneScheduleClient = async (
  id: number,
): Promise<TruckLaneScheduleResponse> => {
  return await getTruckLaneScheduleAction(id);
};

export const pendingTruckLaneScheduleShopIdsClient =
  async (): Promise<PendingTruckRowIdsResponse> => {
    return await pendingTruckLaneScheduleShopIdsAction();
  };

export const cancelTruckLaneScheduleClient = async (
  id: number,
): Promise<TruckLaneScheduleResponse> => {
  return await cancelTruckLaneScheduleAction(id);
};

export const applyNowTruckLaneScheduleClient = async (
  id: number,
): Promise<TruckLaneScheduleResponse> => {
  return await applyNowTruckLaneScheduleAction(id);
};

export const retryFailedTruckLaneScheduleClient = async (
  id: number,
  body?: RetryFailedTruckLaneScheduleRequest,
): Promise<TruckLaneScheduleResponse> => {
  return await retryFailedTruckLaneScheduleAction(id, body);
};

export const ignoreTruckLaneScheduleClient = async (
  id: number,
): Promise<TruckLaneScheduleResponse> => {
  return await ignoreTruckLaneScheduleAction(id);
};

export const parseTruckLaneScheduleExcelClient = async (
  formData: FormData,
  defaultExecuteAt?: string | null,
): Promise<ParseTruckLaneScheduleExcelResponse> => {
  return await parseTruckLaneScheduleExcelAction(formData, defaultExecuteAt);
};

export const importTruckLaneScheduleExcelClient = async (
  formData: FormData,
  defaultExecuteAt?: string | null,
  note?: string | null,
): Promise<TruckLaneScheduleResponse[]> => {
  return await importTruckLaneScheduleExcelAction(
    formData,
    defaultExecuteAt,
    note,
  );
};

export type {
  TruckLaneScheduleResponse,
  TruckLaneScheduleLineResponse,
  TruckLaneMoveTargetRequest,
  TruckLaneScheduleLineRequest,
  CreateTruckLaneScheduleRequest,
  PendingTruckRowIdsResponse,
  ParseTruckLaneScheduleExcelResponse,
  RouteExcelSchedulePlanResponse,
  RouteExcelSchedulePlanPreviewRow,
  RouteExcelSchedulePlanError,
  RouteExcelSchedulePlanCounts,
} from "./actions";

export default fetchAllShopsClient;
