/**
 * 文件职责：订单大厅（看板）接口与类型定义。
 */
import { requestClient } from '#/api/request';

/** 订单看板卡片。 */
export interface OrderBoardCard {
  acceptedAt?: null | string;
  channel: number;
  createdAt: string;
  customerName?: null | string;
  customerPhone?: null | string;
  deliveryType: number;
  id: string;
  isUrged: boolean;
  itemsSummary?: null | string;
  orderNo: string;
  paidAmount: number;
  queueNumber?: null | string;
  readyAt?: null | string;
  status: number;
  storeId: string;
  tableNo?: null | string;
  urgeCount: number;
}

/** 订单看板结果（四列）。 */
export interface OrderBoardResult {
  completed: OrderBoardCard[];
  delivering: OrderBoardCard[];
  making: OrderBoardCard[];
  pending: OrderBoardCard[];
}

/** 订单看板统计。 */
export interface OrderBoardStats {
  completedCount: number;
  deliveringCount: number;
  makingCount: number;
  pendingCount: number;
  todayTotal: number;
}

/** 获取完整看板数据。 */
export async function getOrderBoardApi(params: {
  channel?: string;
  storeId: string;
}) {
  return requestClient.get<OrderBoardResult>('/order-board/board', { params });
}

/** 获取看板统计。 */
export async function getOrderBoardStatsApi(params: { storeId: string }) {
  return requestClient.get<OrderBoardStats>('/order-board/stats', { params });
}

/** 重连补偿拉取。 */
export async function getPendingSinceApi(params: {
  since: string;
  storeId: string;
}) {
  return requestClient.get<OrderBoardCard[]>('/order-board/pending-since', {
    params,
  });
}

/** 接单。 */
export async function acceptOrderApi(orderId: string) {
  return requestClient.post<OrderBoardCard>(
    `/order-board/${orderId}/accept`,
    {},
  );
}

/** 拒单。 */
export async function rejectOrderApi(
  orderId: string,
  data: { reason: string },
) {
  return requestClient.post<OrderBoardCard>(
    `/order-board/${orderId}/reject`,
    data,
  );
}

/** 出餐完成。 */
export async function completePreparationApi(orderId: string) {
  return requestClient.post<OrderBoardCard>(
    `/order-board/${orderId}/complete-preparation`,
    {},
  );
}

/** 确认送达/取餐。 */
export async function confirmDeliveryApi(orderId: string) {
  return requestClient.post<OrderBoardCard>(
    `/order-board/${orderId}/confirm-delivery`,
    {},
  );
}
