const URL = "/one-api/mockup/itemout/";

export async function search(prm) {
  try {
    var response = await axios.post(URL + "itemoutv3/search", prm);
    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(prm) {
  try {
    var response = await axios.post(
      URL + "itemoutv3/searchDetail",
      prm
    );
    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 saveRequest(prm) {
  try {
    var response = await axios.post(
      URL + "itemoutv3/saveRequest",
      prm
    );
    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 updateRequest(prm) {
  try {
    var response = await axios.post(
      URL + "itemoutv3/updateRequest",
      prm
    );
    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 deleteRequest(prm) {
  try {
    var response = await axios.post(
      URL + "itemoutv3/deleteRequest",
      prm
    );
    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 saveDetail(prm) {
  try {
    var response = await axios.post(
      URL + "itemoutv3/saveDetail",
      prm
    );
    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(prm) {
  try {
    var response = await axios.post(
      URL + "itemoutv3/updateDetail",
      prm
    );
    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(prm) {
  try {
    var response = await axios.post(
      URL + "itemoutv3/deleteDetail",
      prm
    );
    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 getWarehouse(prm) {
  try {
    var response = await axios.post(
      URL + "itemoutv3/getWarehouse",
      prm
    );
    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 getDepartment(prm) {
  try {
    var response = await axios.post(
      URL + "itemoutv3/getDepartment",
      prm
    );
    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 searchItem(prm) {
    try {
        var resp = await axios.post(URL + 'itemoutv3/searchItem', prm);
        if (resp.status != 200) {
            return {
                status: "ERR",
                message: resp.statusText
            };
        }
        let data = resp.data;
        return data;
    } catch (e) {
        return {
            status: "ERR",
            message: e.message
        };
    }
}

export async function getUnit(prm) {
    try {
        var resp = await axios.post(URL + 'itemoutv3/getUnit', prm);
        if (resp.status != 200) {
            return {
                status: "ERR",
                message: resp.statusText
            };
        }
        let data = resp.data;
        return data;
    } catch (e) {
        return {
            status: "ERR",
            message: e.message
        };
    }
}

export async function orderConfirm(prm) {
  try {
    var response = await axios.post(
      URL + "itemoutv3/orderConfirm",
      prm
    );
    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 listrequestitem(prm) {
  try {
    var response = await axios.post(URL + "itemoutv3/listrequest", prm);
    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 getDivisionUser(payload) {
  try {
    var response = await axios.post(URL + "RequestItemOut/getDivisionUser", 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(prm) {
  try {
    var response = await axios.post(URL + "itemoutv3/approveRequest", prm);
    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 rejectedRequest(prm) {
  try {
    var response = await axios.post(URL + "itemoutv3/rejectedRequest", prm);
    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 getDivisionByUser(prm) {
  try {
      var resp = await axios.post(URL + 'itemoutv3/getDivisionByUser', prm);
      if (resp.status != 200) {
          return {
              status: "ERR",
              message: resp.statusText
          };
      }
      let data = resp.data;
      return data;
  } catch (e) {
      return {
          status: "ERR",
          message: e.message
      };
  }
}

export async function getItemRequest(prm) {
  try {
      var resp = await axios.post(URL + 'itemoutv3/getItemRequest', prm);
      if (resp.status != 200) {
          return {
              status: "ERR",
              message: resp.statusText
          };
      }
      let data = resp.data;
      return data;
  } catch (e) {
      return {
          status: "ERR",
          message: e.message
      };
  }
}

export async function getDetailItemOut(prm) {
  try {
      var resp = await axios.post(URL + 'itemoutv3/getDetailItemOut', prm);
      if (resp.status != 200) {
          return {
              status: "ERR",
              message: resp.statusText
          };
      }
      let data = resp.data;
      return data;
  } catch (e) {
      return {
          status: "ERR",
          message: e.message
      };
  }
}

export async function getItemOuts(prm) {
  try {
      var resp = await axios.post(URL + 'itemoutv3/getItemOuts', prm);
      if (resp.status != 200) {
          return {
              status: "ERR",
              message: resp.statusText
          };
      }
      let data = resp.data;
      return data;
  } catch (e) {
      return {
          status: "ERR",
          message: e.message
      };
  }
}

export async function confirmIO(prm) {
  try {
      var resp = await axios.post(URL + 'itemoutv3/confirmIO', prm);
      if (resp.status != 200) {
          return {
              status: "ERR",
              message: resp.statusText
          };
      }
      let data = resp.data;
      return data;
  } catch (e) {
      return {
          status: "ERR",
          message: e.message
      };
  }
}

export async function approveIO(prm) {
  try {
      var resp = await axios.post(URL + 'itemoutv3/approveIO', prm);
      if (resp.status != 200) {
          return {
              status: "ERR",
              message: resp.statusText
          };
      }
      let data = resp.data;
      return data;
  } catch (e) {
      return {
          status: "ERR",
          message: e.message
      };
  }
}

export async function processIO(prm) {
  try {
      var resp = await axios.post(URL + 'itemoutv3/processIO', prm);
      if (resp.status != 200) {
          return {
              status: "ERR",
              message: resp.statusText
          };
      }
      let data = resp.data;
      return data;
  } catch (e) {
      return {
          status: "ERR",
          message: e.message
      };
  }
}

export async function rejectRequest(prm) {
  try {
      var resp = await axios.post(URL + 'itemoutv3/rejectRequest', prm);
      if (resp.status != 200) {
          return {
              status: "ERR",
              message: resp.statusText
          };
      }
      let data = resp.data;
      return data;
  } catch (e) {
      return {
          status: "ERR",
          message: e.message
      };
  }
}

export async function getItemBatchListing(params) {
    try {
        var resp = await axios.post(URL + "itemoutv3/getItemBatchListing", params);
        if (resp.status !== 200) {
            return {
                status: "ERR",
                message: resp.message
            }
        }

        let data = resp.data
        return data
    } catch (error) {
        return {
            status: "ERR",
            message: error.message
        }
    }
}

export async function getlevel(prm) {
  try {
    var resp = await axios.post(URL + "itemoutv3/getlevel", prm);
    if (resp.status !== 200) {
      return {
        status: "ERR",
        message: resp.statusText,
      };
    }

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