package org.springblade.common.upyzt.model;

import org.springblade.common.upyzt.exception.UpyztException;
import org.springblade.common.upyzt.net.APIResource;
import org.springblade.common.upyzt.net.RequestOptions;
import org.springblade.common.upyzt.resp.WithdrawalApplicationResp;
import org.springblade.common.upyzt.resp.WithdrawalConfirmResp;
import java.util.Map;
import lombok.experimental.Accessors;

/**
 * 提现申请
 */
@Accessors(chain = true)
public class WithdrawalApplication extends APIResource {

    /**
     * 提现
     *
     * @param params 请求参数
     * @return 返回参数
     * @throws UpyztException 异常
     */
    public static WithdrawalApplicationResp create(Map<String, Object> params) throws UpyztException {
        return create(params, null);
    }

    /**
     * 提现
     *
     * @param params  请求参数
     * @param options 参数选项
     * @return 返回参数
     * @throws UpyztException 异常
     */
    public static WithdrawalApplicationResp create(Map<String, Object> params, RequestOptions options) throws UpyztException {
        return APIResource.request(RequestMethod.POST,
            classURL(WithdrawalApplication.class), params,
            WithdrawalApplicationResp.class, options);
    }

    /**
     * 提现申请取消
     *
     * @param withdrawalId 提现申请id
     * @return 返回参数
     */
    public static WithdrawalApplicationResp cancel(String withdrawalId) throws UpyztException {
        return APIResource.request(RequestMethod.PUT,
            instanceURL(WithdrawalApplication.class, withdrawalId)+ "/cancel", null,
            WithdrawalApplicationResp.class, null);
    }

    /**
     * 提现订单查询（系统订单号）
     *
     * @param id 系统订单号
     * @return 返回参数
     * @throws UpyztException 异常
     */
    public static WithdrawalApplicationResp retrieveById(String id) throws UpyztException {
        return retrieveById(id, null);
    }

    /**
     * 提现订单查询（系统订单号）
     *
     * @param id      系统订单号
     * @param options 参数选项
     * @return 返回参数
     * @throws UpyztException 异常
     */
    public static WithdrawalApplicationResp retrieveById(String id, RequestOptions options) throws UpyztException {
        return APIResource.request(RequestMethod.GET,
            instanceURL(WithdrawalApplication.class, id), null,
            WithdrawalApplicationResp.class, options);
    }

    /**
     * 提现订单查询（平台订单号）
     *
     * @param outOrderNo 平台订单号
     * @return 返回参数
     * @throws UpyztException 异常
     */
    public static WithdrawalApplicationResp retrieveByOutOrderNo(String outOrderNo) throws UpyztException {
        return retrieveByOutOrderNo(outOrderNo, null);
    }

    /**
     * 提现订单查询（平台订单号）
     *
     * @param outOrderNo 平台订单号
     * @param options    参数选项
     * @return 返回参数
     * @throws UpyztException 异常
     */
    public static WithdrawalApplicationResp retrieveByOutOrderNo(String outOrderNo, RequestOptions options) throws UpyztException {
        return APIResource
            .request(RequestMethod.GET,
                instanceURL(WithdrawalApplication.class, "_by_out_order_no", outOrderNo), null,
                WithdrawalApplicationResp.class, options);
    }
}
