/**
 * 文件职责：订单大厅本地类型定义。
 */
import type { OrderBoardCard } from '#/api/order-hall';
import type { StoreListItemDto } from '#/api/store';

/** 看板列键。 */
export type BoardColumnKey = 'completed' | 'delivering' | 'making' | 'pending';

/** 履约类型筛选值。 */
export type BoardDeliveryFilter = 'all' | 'delivery' | 'dineIn' | 'pickup';

/** 门店下拉选项。 */
export interface StoreOptionItem {
  label: string;
  value: string;
}

/** SignalR 新订单推送载荷。 */
export interface NewOrderPayload {
  amount: number;
  channel: number;
  createdAt: string;
  customerName?: null | string;
  deliveryType: number;
  itemsSummary?: null | string;
  orderId: number;
  orderNo: string;
  storeId: number;
  tableNo?: null | string;
}

/** SignalR 状态变更推送载荷。 */
export interface OrderStatusChangedPayload {
  channel: number;
  customerName?: null | string;
  deliveryType: number;
  itemsSummary?: null | string;
  newStatus: number;
  occurredAt: string;
  oldStatus: number;
  orderId: number;
  orderNo: string;
  paidAmount: number;
}

/** SignalR 催单推送载荷。 */
export interface OrderUrgedPayload {
  occurredAt: string;
  orderId: number;
  orderNo: string;
  urgeCount: number;
}

/** 看板页面状态。 */
export interface OrderHallPageState {
  deliveryFilter: BoardDeliveryFilter;
  completedCards: OrderBoardCard[];
  deliveringCards: OrderBoardCard[];
  isStoreLoading: boolean;
  isLoading: boolean;
  isSoundEnabled: boolean;
  makingCards: OrderBoardCard[];
  pendingCards: OrderBoardCard[];
  selectedStoreId: string;
  storeOptions: StoreOptionItem[];
}

/** 订单大厅统计状态。 */
export interface OrderHallStatsState {
  completedCount: number;
  deliveringCount: number;
  makingCount: number;
  pendingCount: number;
  todayTotal: number;
}

/** 门店列表与选项转换。 */
export function mapStoreOptions(stores: StoreListItemDto[]): StoreOptionItem[] {
  return stores.map((item) => ({
    label: item.name,
    value: item.id,
  }));
}
