export default function useNFCPatrolRoute() {
  function getAll({
    page = 1,
    limit = 20,
    site = "",
    search = "",
  } = {}) {
    const query: Record<string, any> = {
      page,
      limit,
      site,
    };
    
    // Only include search parameter if it has a value
    if (search) {
      query.search = search;
    }
    
    return useNuxtApp().$api<Record<string, any>>(`/api/nfc-patrol-route`, {
      method: "GET",
      query,
    });
  }

  function add(value: {
    name: string;
    checkPointNumber: number;
    tolerance: string;
    days: number[];
    startTimes: string[];
    checkPoints: Array<{ nfcTag_id: string; travelTime: number }>;
    site: string;
  }) {
    return useNuxtApp().$api<Record<string, any>>("/api/nfc-patrol-route", {
      method: "POST",
      body: value,
    });
  }

  function getById(id: string) {
    return useNuxtApp().$api<Record<string, any>>(`/api/nfc-patrol-route/id/${id}`, {
      method: "GET",
    });
  }

  function deleteById(id: string) {
    return useNuxtApp().$api(`/api/nfc-patrol-route/${id}`, {
      method: "DELETE",
    });
  }

  function updateById(
    id: string,
    value: {
      name: string;
      checkPointNumber: number;
      tolerance: string;
      days: number[];
      startTimes: string[];
      checkPoints: Array<{ nfcTag_id: string; travelTime: number }>;
      site: string;
    }
  ) {
    return useNuxtApp().$api(`/api/nfc-patrol-route/id/${id}`, {
      method: "PATCH",
      body: value,
    });
  }

  return {
    getAll,
    getById,
    add,
    deleteById,
    updateById,
  };
}
