import axios from "@/lib/axios";

class ProductApiService {
  async sync(items: ISyncItem[]) {
    try {
      const { data } = await axios.post("/products/sync", {
        items,
      });
      console.log("[NestJS] Response (bulk):", data);
      return data;
    } catch (err) {
      console.error("[NestJS] Error (bulk):", err);
      throw err;
    }
  }

  finistPublist = async (
    item: IItem,
    values: { error?: string; published: boolean; message?: string }
  ) => {
    const { data } = await axios({
      url: "products/publist-finish/" + item.id,
      method: "POST",
      data: values,
    });

    return data;
  };

  updatePublist = async (
    item: IItem,
    values: {
      error?: string;
      published: boolean;
      message?: string;
      publist_id?: string;
    }
  ) => {
    const { data } = await axios({
      url: "products/update-finish/" + item.id,
      method: "POST",
      data: values,
    });

    return data;
  };

  finistDelete = async (
    item: IItem,
    values: { error?: string; published: boolean }
  ) => {
    const { data } = await axios({
      url: "products/delete-finish/" + item.id,
      method: "POST",
      data: values,
    });

    return data;
  };
}

export const productApi = new ProductApiService();
