package com.bonus.core.pay.channel.ali.api;

import com.bonus.core.pay.channel.ali.extension.AliPayExtension;
import com.bonus.core.pay.common.constants.PayStateEnum;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;

@Component
public class AlipayAPI {
   private final AliPayExtension aliPay;

   public AlipayAPI(AliPayExtension aliPay) {
      this.aliPay = aliPay;
   }

   public static class EnterpriseCodeResponse {
      private Integer code;
      private String msg;
      private String outTradeNo;
      private String accountId;
      private String totalAmount;
      private String openId;

      public static EnterpriseCodeResponse success() {
         EnterpriseCodeResponse response = new EnterpriseCodeResponse();
         response.setCode(PayStateEnum.PAY_SUCC.getKey());
         return response;
      }

      public static EnterpriseCodeResponse fail(String message) {
         EnterpriseCodeResponse response = new EnterpriseCodeResponse();
         response.setCode(PayStateEnum.PAY_FAIL.getKey());
         response.setMsg(message);
         return response;
      }

      public static EnterpriseCodeResponse fail(String message, EnterpriseCodeAliParam param) {
         EnterpriseCodeResponse response = new EnterpriseCodeResponse();
         response.setCode(PayStateEnum.PAY_FAIL.getKey());
         response.setMsg(message);
         response.setAccountId(param.getAccountId());
         response.setTotalAmount(param.getTotalAmount());
         response.setOutTradeNo(param.getOutTradeNo());
         response.setOpenId(param.getOpenId());
         return response;
      }

      public static EnterpriseCodeResponse progress() {
         EnterpriseCodeResponse response = new EnterpriseCodeResponse();
         response.setCode(PayStateEnum.PAY_INPROCESS.getKey());
         response.setMsg(PayStateEnum.PAY_INPROCESS.getDesc());
         return response;
      }

      public Integer getCode() {
         return this.code;
      }

      public String getMsg() {
         return this.msg;
      }

      public String getOutTradeNo() {
         return this.outTradeNo;
      }

      public String getAccountId() {
         return this.accountId;
      }

      public String getTotalAmount() {
         return this.totalAmount;
      }

      public String getOpenId() {
         return this.openId;
      }

      public void setCode(final Integer code) {
         this.code = code;
      }

      public void setMsg(final String msg) {
         this.msg = msg;
      }

      public void setOutTradeNo(final String outTradeNo) {
         this.outTradeNo = outTradeNo;
      }

      public void setAccountId(final String accountId) {
         this.accountId = accountId;
      }

      public void setTotalAmount(final String totalAmount) {
         this.totalAmount = totalAmount;
      }

      public void setOpenId(final String openId) {
         this.openId = openId;
      }
   }
   public static class EnterpriseCodeAliParam {
      private String outTradeNo;
      private String accountId;
      private String totalAmount;
      private String alreadyPaid;
      private String openId;
      private String terminalParams;
      private String alipayContractNum;
      private Long canteenId;
      private boolean async;

      EnterpriseCodeAliParam(final String outTradeNo, final String accountId, final String totalAmount, final String alreadyPaid, final String openId, final String terminalParams, final String alipayContractNum, final Long canteenId, final boolean async) {
         this.outTradeNo = outTradeNo;
         this.accountId = accountId;
         this.totalAmount = totalAmount;
         this.alreadyPaid = alreadyPaid;
         this.openId = openId;
         this.terminalParams = terminalParams;
         this.alipayContractNum = alipayContractNum;
         this.canteenId = canteenId;
         this.async = async;
      }

      public static EnterpriseCodeAliParamBuilder builder() {
         return new EnterpriseCodeAliParamBuilder();
      }

      public String getOutTradeNo() {
         return this.outTradeNo;
      }

      public String getAccountId() {
         return this.accountId;
      }

      public String getTotalAmount() {
         return this.totalAmount;
      }

      public String getAlreadyPaid() {
         return this.alreadyPaid;
      }

      public String getOpenId() {
         return this.openId;
      }

      public String getTerminalParams() {
         return this.terminalParams;
      }

      public String getAlipayContractNum() {
         return this.alipayContractNum;
      }

      public Long getCanteenId() {
         return this.canteenId;
      }

      public boolean isAsync() {
         return this.async;
      }

      public void setOutTradeNo(final String outTradeNo) {
         this.outTradeNo = outTradeNo;
      }

      public void setAccountId(final String accountId) {
         this.accountId = accountId;
      }

      public void setTotalAmount(final String totalAmount) {
         this.totalAmount = totalAmount;
      }

      public void setAlreadyPaid(final String alreadyPaid) {
         this.alreadyPaid = alreadyPaid;
      }

      public void setOpenId(final String openId) {
         this.openId = openId;
      }

      public void setTerminalParams(final String terminalParams) {
         this.terminalParams = terminalParams;
      }

      public void setAlipayContractNum(final String alipayContractNum) {
         this.alipayContractNum = alipayContractNum;
      }

      public void setCanteenId(final Long canteenId) {
         this.canteenId = canteenId;
      }

      public void setAsync(final boolean async) {
         this.async = async;
      }


      public static class EnterpriseCodeAliParamBuilder {
         private String outTradeNo;
         private String accountId;
         private String totalAmount;
         private String alreadyPaid;
         private String openId;
         private String terminalParams;
         private String alipayContractNum;
         private Long canteenId;
         private boolean async;

         EnterpriseCodeAliParamBuilder() {
         }

         public EnterpriseCodeAliParamBuilder outTradeNo(final String outTradeNo) {
            this.outTradeNo = outTradeNo;
            return this;
         }

         public EnterpriseCodeAliParamBuilder accountId(final String accountId) {
            this.accountId = accountId;
            return this;
         }

         public EnterpriseCodeAliParamBuilder totalAmount(final String totalAmount) {
            this.totalAmount = totalAmount;
            return this;
         }

         public EnterpriseCodeAliParamBuilder alreadyPaid(final String alreadyPaid) {
            this.alreadyPaid = alreadyPaid;
            return this;
         }

         public EnterpriseCodeAliParamBuilder openId(final String openId) {
            this.openId = openId;
            return this;
         }

         public EnterpriseCodeAliParamBuilder terminalParams(final String terminalParams) {
            this.terminalParams = terminalParams;
            return this;
         }

         public EnterpriseCodeAliParamBuilder alipayContractNum(final String alipayContractNum) {
            this.alipayContractNum = alipayContractNum;
            return this;
         }

         public EnterpriseCodeAliParamBuilder canteenId(final Long canteenId) {
            this.canteenId = canteenId;
            return this;
         }

         public EnterpriseCodeAliParamBuilder async(final boolean async) {
            this.async = async;
            return this;
         }

         public EnterpriseCodeAliParam build() {
            return new EnterpriseCodeAliParam(this.outTradeNo, this.accountId, this.totalAmount, this.alreadyPaid, this.openId, this.terminalParams, this.alipayContractNum, this.canteenId, this.async);
         }

         public String toString() {
            return "AlipayAPI.EnterpriseCodeAliParam.EnterpriseCodeAliParamBuilder(outTradeNo=" + this.outTradeNo + ", accountId=" + this.accountId + ", totalAmount=" + this.totalAmount + ", alreadyPaid=" + this.alreadyPaid + ", openId=" + this.openId + ", terminalParams=" + this.terminalParams + ", alipayContractNum=" + this.alipayContractNum + ", canteenId=" + this.canteenId + ", async=" + this.async + ")";
         }
      }
   }

   public static class HoldingResponse {
      private Integer code;
      private String msg;
      private String outTradeNo;

      public Integer getCode() {
         return this.code;
      }

      public String getMsg() {
         return this.msg;
      }

      public String getOutTradeNo() {
         return this.outTradeNo;
      }

      public void setCode(final Integer code) {
         this.code = code;
      }

      public void setMsg(final String msg) {
         this.msg = msg;
      }

      public void setOutTradeNo(final String outTradeNo) {
         this.outTradeNo = outTradeNo;
      }
   }

   public static class HoldingParam {
      private Long tradeId;
      private BigDecimal amount;
      private Integer payType;
      private Long custId;
      private Long canteenId;
      private String canteenName;
      private String authCode;
      private String terminalParams;
      private String alipayContractNum;
      private String openid;

      public Long getTradeId() {
         return this.tradeId;
      }

      public BigDecimal getAmount() {
         return this.amount;
      }

      public Integer getPayType() {
         return this.payType;
      }

      public Long getCustId() {
         return this.custId;
      }

      public Long getCanteenId() {
         return this.canteenId;
      }

      public String getCanteenName() {
         return this.canteenName;
      }

      public String getAuthCode() {
         return this.authCode;
      }

      public String getTerminalParams() {
         return this.terminalParams;
      }

      public String getAlipayContractNum() {
         return this.alipayContractNum;
      }

      public String getOpenid() {
         return this.openid;
      }

      public void setTradeId(final Long tradeId) {
         this.tradeId = tradeId;
      }

      public void setAmount(final BigDecimal amount) {
         this.amount = amount;
      }

      public void setPayType(final Integer payType) {
         this.payType = payType;
      }

      public void setCustId(final Long custId) {
         this.custId = custId;
      }

      public void setCanteenId(final Long canteenId) {
         this.canteenId = canteenId;
      }

      public void setCanteenName(final String canteenName) {
         this.canteenName = canteenName;
      }

      public void setAuthCode(final String authCode) {
         this.authCode = authCode;
      }

      public void setTerminalParams(final String terminalParams) {
         this.terminalParams = terminalParams;
      }

      public void setAlipayContractNum(final String alipayContractNum) {
         this.alipayContractNum = alipayContractNum;
      }

      public void setOpenid(final String openid) {
         this.openid = openid;
      }
   }
}
