import { lotteryRequest } from "@/lib/lottery-http";
import type {
  TicketDrawMyMatchPayload,
  TicketItemDetailPayload,
  TicketItemsListPayload,
} from "@/types/api/ticket-items";

export type GetTicketItemsParams = {
  page?: number;
  per_page?: number;
  draw_no?: string;
  order_no?: string;
  number?: string;
  status?: string[];
  start_date?: string;
  end_date?: string;
};

/** `GET /api/v1/ticket/items`（需登录） */
export function getTicketItems(
  params?: GetTicketItemsParams,
): Promise<TicketItemsListPayload> {
  return lotteryRequest.get<TicketItemsListPayload>(
    `/ticket/items`,
    {
      params: {
        page: params?.page,
        per_page: params?.per_page,
        draw_no: params?.draw_no,
        order_no: params?.order_no,
        number: params?.number,
        status: params?.status,
        start_date: params?.start_date,
        end_date: params?.end_date,
      },
    },
  );
}

/** `GET /api/v1/ticket/items/{ticket_no}`（需登录） */
export function getTicketItemDetail(
  ticketNo: string,
): Promise<TicketItemDetailPayload> {
  const enc = encodeURIComponent(ticketNo);
  return lotteryRequest.get<TicketItemDetailPayload>(
    `/ticket/items/${enc}`,
  );
}

/** `GET /api/v1/ticket/draws/{draw_no}/my-match`（需登录） */
export function getTicketDrawMyMatch(
  drawNo: string,
): Promise<TicketDrawMyMatchPayload> {
  const enc = encodeURIComponent(drawNo);
  return lotteryRequest.get<TicketDrawMyMatchPayload>(
    `/ticket/draws/${enc}/my-match`,
  );
}
