import ApiConnect2 from "./ApiConfig2";

//Get All User Transactions
export const get_user_transactions = async (data) => {
  // console.log(data)
  try {
    if (!data.id) {
      throw new Error("data.id is empty or undefined");
    }
    const result = await ApiConnect2(`transactions/user/${data.id}`, {
      method: "GET",
      headers: {
        Authorization: `Bearer ${data.token}`,
      },
    });
    return result;
  } catch (error) {
    console.log(error);
    console.log(error + "failed get user transaction api");

    return error;
  }
};

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

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

    return error;
  }
};
//CREATE TRANSACTION
export const create_transaction = async (data) => {
  // console.log(data)
  try {
    const result = await ApiConnect2(`transactions/create`, {
      method: "POST",
      data: data.body,
      headers: {
        Authorization: `Bearer ${data.token}`,
      },
    });
    return result;
  } catch (error) {
    console.log(error);
    console.log(error + "failed create user transaction api");

    return error;
  }
};

// export const update_transaction = async (data) => {
//   // console.log(data)
//   try {
//     const result = await ApiConnect2(`transactions/update/${data.id}`, {
//       method: "POST",
//       data: data.body,
//       headers: {
//         "Authorization": `Bearer ${data.token}`
//       }
//     });
//     return result;
//   } catch (error) {
//     console.log(error)
//     return error;
//   }
// };
//CREATE notification
export const create_notification = async (data) => {
  // console.log(data)
  try {
    const result = await ApiConnect2(`notifications/create`, {
      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 user notification api");

    return error;
  }
};