const URL = "/one-api/mockup/masterdata/accounting/";

export async function getRegional(prm) {
  try {
    var resp = await axios.post(URL + "bankcoa/getRegional", 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 getBranch(prm) {
  try {
    var resp = await axios.post(URL + "bankcoa/getBranch", 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 search(prm) {
  try {
    var resp = await axios.post(URL + "bankcoa/search", 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 searchCoaBank(token, prm) {
    try {
        var resp = await axios.post(URL + 'bankcoa/searchCoaBank', {
            token: token,
            search: 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 searchCoaEDC(token, prm) {
    try {
        var resp = await axios.post(URL + 'bankcoa/searchCoaEDC', {
            token: token,
            search: 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 saveupdate(prm) {
    try {
        var resp = await axios.post(URL + 'bankcoa/saveupdate', 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 deletebankcoa(prm) {
    try {
        var resp = await axios.post(URL + 'bankcoa/deletebankcoa', 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 importBank(branchCode) {
    try {
        var resp = await axios.get(URL + `Mediajurnalauto/injectMapBankCab/${branchCode}`);
        if (resp.status != 200) {
            return {
                status: "ERR",
                message: resp.statusText
            };
        }
        let data = resp.data;
        return data;
    } catch (e) {
        return {
            status: "ERR",
            message: e.message
        };
    }
}