import ApiConnect from "../ApiConfig";

//Get All vendors

export const get_all_vendors = async () => {
  // console.log(data)
  try {
    // if (!data.id) {
    //   throw new Error("data.id is empty or undefined");
    // }
    const result = await ApiConnect(`vendors`, {
      method: "GET",
    });
    return result;
  } catch (error) {
    console.log(error);
    console.log(error + "failed get all vendors api");

    return error;
  }
};
//Get a notification
export const get_vendor = async (data) => {
  // console.log(data)
  try {
    if (!data.id) {
      throw new Error("data.id is empty or undefined");
    }
    const result = await ApiConnect(`vendors/${data.id}`, {
      method: "GET",
      // data: data,
      //   headers: {
      //     Authorization: `Bearer ${data.token}`,
      //   },
    });
    return result;
  } catch (error) {
    console.log(error);
    console.log(error + "failed get vendor api");

    return error;
  }
};
//CREATE vendor
export const create_vendor = async (data) => {
  // console.log(data)
  try {
    const result = await ApiConnect(`vendors`, {
      method: "POST",
      data: data.body,
      //   headers: {
      //     Authorization: `Bearer ${data.token}`,
      //   },
    });
    console.log("created");
    return result;
  } catch (error) {
    console.log(error);
    console.log(error + "failed create vendor api");

    return error;
  }
};
export const search_vendor = async (data) => {
  // console.log(data)
  try {
    if (!data.searchData) {
      throw new Error("data.id is empty or undefined");
    }
    const result = await ApiConnect(`vendors/search?q=${data.searchData}`, {
      method: "GET",
      // data: data,
      //   headers: {
      //     Authorization: `Bearer ${data.token}`,
      //   },
    });
    return result;
  } catch (error) {
    console.log(error);
    console.log(error + "failed get vendor api");

    return error;
  }
};
export const update_vendor = async (data) => {
  // console.log(data)
  try {
    if (!data.id) {
      throw new Error("data.id is empty or undefined");
    }
    const result = await ApiConnect(`vendors/${data.id}`, {
      method: "PATCH",
      data: data.body,
      //   headers: {
      //     Authorization: `Bearer ${data.token}`,
      //   },
    });
    return result;
  } catch (error) {
    console.log(error + "failed update vendor api");
    return error;
  }
};
