const URL = "/one-api/mockup/purchase/manager/";

export async function search(payload) {
  try {
    var response = await axios.post(URL + "purchaseRequestDirectApproved/search", payload);
    if (response.status !== 200) {
      return {
        status: "ERR",
        message: response.statusText,
      };
    }

    let data = response.data;
    return data;
  } catch (e) {
    return {
      status: "ERR",
      message: e.message,
    };
  }
}
export async function getlevel(payload) {
  try {
    var response = await axios.post(URL + "purchaseRequestDirectApproved/getlevel", payload);
    if (response.status !== 200) {
      return {
        status: "ERR",
        message: response.statusText,
      };
    }

    let data = response.data;
    return data;
  } catch (e) {
    return {
      status: "ERR",
      message: e.message,
    };
  }
}
export async function searchDetail(payload) {
  try {
    var response = await axios.post(
      URL + "purchaseRequestDirectApproved/searchDetail",
      payload
    );
    if (response.status !== 200) {
      return {
        status: "ERR",
        message: response.statusText,
      };
    }

    let data = response.data;
    return data;
  } catch (e) {
    return {
      status: "ERR",
      message: e.message,
    };
  }
}

export async function deleteDetail(payload) {
  try {
    var response = await axios.post(
      URL + "purchaseRequestDirectApproved/deleteDetail",
      payload
    );
    if (response.status !== 200) {
      return {
        status: "ERR",
        message: response.statusText,
      };
    }

    let data = response.data;
    return data;
  } catch (e) {
    return {
      status: "ERR",
      message: e.message,
    };
  }
}

export async function approveRequest(payload) {
  try {
    var response = await axios.post(
      URL + "purchaseRequestDirectApproved/approveRequest",
      payload
    );
    if (response.status !== 200) {
      return {
        status: "ERR",
        message: response.statusText,
      };
    }

    let data = response.data;
    return data;
  } catch (e) {
    return {
      status: "ERR",
      message: e.message,
    };
  }
}

export async function rejectRequest(payload) {
  try {
    var response = await axios.post(
      URL + "purchaseRequestDirectApproved/rejectRequest",
      payload
    );
    if (response.status !== 200) {
      return {
        status: "ERR",
        message: response.statusText,
      };
    }

    let data = response.data;
    return data;
  } catch (e) {
    return {
      status: "ERR",
      message: e.message,
    };
  }
}

export async function unApproveRequest(payload) {
  try {
    var response = await axios.post(
      URL + "purchaseRequestDirectApproved/unApproveRequest",
      payload
    );
    if (response.status !== 200) {
      return {
        status: "ERR",
        message: response.statusText,
      };
    }

    let data = response.data;
    return data;
  } catch (e) {
    return {
      status: "ERR",
      message: e.message,
    };
  }
}

export async function updateDetail(payload) {
  try {
    var response = await axios.post(
      URL + "purchaseRequestDirectApproved/updateDetail",
      payload
    );
    if (response.status !== 200) {
      return {
        status: "ERR",
        message: response.statusText,
      };
    }

    let data = response.data;
    return data;
  } catch (e) {
    return {
      status: "ERR",
      message: e.message,
    };
  }
}
