import { TFOutput } from '../TFOutput'
import { TFInput } from '../TFInput'
import type { Message } from '../../Communication/Message'
import type { PageBase } from '../../ContractBase/PageBase'

/**
 * 冻结止付扣划预判
 */
export class AnticipationFreezeStoppaymentDeduct extends TFOutput {
    /**
     * 可扣划金额 0400
     */
    public KKHJE: string = ''

    /**
     * 已扣划金额 0410
     */
    public YKHJE: string = ''
}

/**
 * 参数清单
 */
export class AnticipationFreezeStoppaymentDeductInput extends TFInput {
    /**
     * 账号 0310
     */
    public ZH: string = ''

    /**
     * 账户序号 0340
     */
    public ZHXH: string = ''

    /**
     * 冻结序号 0350
     */
    public DJXH: string = ''

    /**
     * 扣划金额 0400
     */
    public KHJE: string = ''

    /**
     * 销户标志 0690
     * 1:销户 0:不销户
     */
    public XHBZ: string = ''

    /**
     * 扣划类型 0700
     * {"冻结扣划", "2" }, { "止付扣划", "4" }, { "直接扣划", "1" }, { "其他扣划", "3" }, {"特殊扣划","5"}
     */
    public KHLX: string = ''

    /**
     * 定义业务逻辑
     */
    public override Raise(): AnticipationFreezeStoppaymentDeduct {
        const output = new AnticipationFreezeStoppaymentDeduct()
        
        this.PageData.TradeAPIs.InitFd(this.MessageData)
        this.PageData.TradeAPIs.CommSend(this.MessageData)
        
        this.MessageData.Fd126_5 = this.MainCode
        this.MessageData.Fd16 = "K058"
        this.MessageData.Fd31 = this.ZH
        this.MessageData.Fd34 = this.ZHXH
        this.MessageData.Fd35 = this.DJXH
        this.MessageData.Fd40 = this.KHJE
        this.MessageData.Fd69 = this.XHBZ
        this.MessageData.Fd70 = this.KHLX

        this.PageData.TradeAPIs.CallServer(this.MessageData)
        
        if (this.MessageData.Fd12 !== "0000") {
            output.IsFailed = true
            output.FailureCause = this.PageData.TradeAPIs.GetError(this.MessageData)
        }
        
        output.KKHJE = this.MessageData.Fd40
        output.YKHJE = this.MessageData.Fd41

        return output
    }
}

// Vue组合式API封装
export const useAnticipationFreezeStoppaymentDeduct = () => {
    return {
        AnticipationFreezeStoppaymentDeduct,
        AnticipationFreezeStoppaymentDeductInput
    }
}