package com.ywt.outpatient.domain.models.config;

import java.io.Serializable;

/**
 * 工行支付配置
 */
public class IcbcPayConfig implements Serializable {

    // {"prescription_icbc_is_open":"0","pay_code":"1005","proportion":"1:1"}
    // 工行支付配置，用于广三支付,prescription_icbc_is_open:0-关闭，1-开启，pay_code对应icbc_vendor表中的pay_code，proportion：表示wechat : icbc
    /**
     * 处方支付是否开启，0-关闭，1-开启
     */
    private Integer prescription_icbc_is_open;

    /**
     * 支付比例：wechat : icbc，eg：1:1
     * 注： 处方支付开启之后，比例才生效
     */
    private String proportion;

    public boolean getPrescriptionIcbcIsOpen() {
        if (prescription_icbc_is_open > 0)
            return true;
        return false;
    }

    public void setPrescriptionIcbcIsOpen(Integer prescriptionIcbcIsOpen) {
        this.prescription_icbc_is_open = prescriptionIcbcIsOpen;
    }

    public String getProportion() {
        return proportion;
    }

    public void setProportion(String proportion) {
        this.proportion = proportion;
    }

    /**
     * 得到比例中微信支付的初始次数(前提，必须先打开icbc配置)
     *
     * @return 次数
     */
    public int getWechatPayInitCount() {
        try {
            String[] arr = proportion.split(":");
            if (getPrescriptionIcbcIsOpen() && arr != null && arr.length == 2) {
                return Math.abs(Integer.parseInt(arr[0]));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return 1;
    }

    /**
     * 得到比例中工行支付的初始次数(前提，必须先打开icbc配置)
     *
     * @return 次数
     */
    public int getIcbcPayInitCount() {
        try {
            String[] arr = proportion.split(":");
            if (getPrescriptionIcbcIsOpen() && arr != null && arr.length == 2) {
                return Math.abs(Integer.parseInt(arr[1]));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return 0;
    }

    @Override
    public String toString() {
        return "IcbcPayConfig{" +
                "prescription_icbc_is_open=" + prescription_icbc_is_open +
                ", proportion='" + proportion + '\'' +
                '}';
    }
}
