import type { ApiResponse } from "@/lib/api"
import { callPublic } from "./base"

export type LineItem = {
  city: string | number
  daikuan: string | number
  name: string | number
  nasname: string | number
  online: string | number
  supply: string | number
}

export type LineData = {
  count: number | string
  use_count: number | string
  data: LineItem[]
}

export type LineSearchResult = {
  data: LineItem[]
}

export async function fetchLineData(
  product: number,
): Promise<ApiResponse<LineData>> {
  return await callPublic<LineData>(
    `/script/linedata/display.php?product=${product}`,
    undefined,
    "GET",
  )
}

export async function searchLineData(
  productid: number,
  info: string,
): Promise<ApiResponse<LineSearchResult>> {
  const query = `type=0&productid=${productid}&info=${encodeURIComponent(info)}`
  return await callPublic<LineSearchResult>(
    `/script/linedata/search.php?${query}`,
    undefined,
    "GET",
  )
}
