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

/**
 * 具体账户利息测算
 * 通过账号计算账户利息
 */
export class AccountInterestCalculation extends TFOutput {
    /**
     * 应付利息 102P
     */
    public YFLX: string = ''

    /**
     * 利息税 102Q
     */
    public LXS: string = ''

    /**
     * 保值利息 102R
     */
    public BZLX: string = ''

    /**
     * 本息合计 102S
     */
    public BXHJ: string = ''
}

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

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

    /**
     * 支取金额 0400
     */
    public ZQJE: string = ''

    /**
     * 交易日期 0440
     */
    public JYRQ: string = ''

    /**
     * 支取方式 0700
     * 定期账户支取方式：1:销户，2:部提 活期(不销户，不计息) 空值默认:销户
     */
    public ZQFS: string = ''

    /**
     * 是否有教育证明 0710
     * 1:有 0:没有，空值默认没有
     */
    public SFJYZM: string = ''

    /**
     * 执行利率标志（通知存款特殊要求）
     * 0: 活期利率, 1:一天通知存款利率,2:七天通知存款利率,3:系统计算利率,空值默认没有
     */
    public ZXLLBZ: string = ''

    /**
     * 定义业务逻辑
     */
    public override Raise(): AccountInterestCalculation {
        const output = new AccountInterestCalculation()
        
        this.PageData.TradeAPIs.InitFd(this.MessageData)
        this.PageData.TradeAPIs.CommSend(this.MessageData)
        
        this.MessageData.Fd126_5 = this.MainCode
        this.MessageData.Fd16 = "K026"
        this.MessageData.Fd20 = this.ZXLLBZ
        this.MessageData.Fd30 = this.ZH
        this.MessageData.Fd34 = this.ZHXH
        this.MessageData.Fd40 = this.ZQJE
        this.MessageData.Fd44 = this.JYRQ
        this.MessageData.Fd70 = this.ZQFS
        this.MessageData.Fd71 = this.SFJYZM

        this.PageData.TradeAPIs.CallServer(this.MessageData)
        
        if (this.MessageData.Fd12 !== "0000") {
            output.IsFailed = true
            output.FailureCause = this.PageData.TradeAPIs.GetError(this.MessageData)
        }
        
        output.YFLX = this.MessageData.Fd102_P
        output.LXS = this.MessageData.Fd102_Q
        output.BZLX = this.MessageData.Fd102_R
        output.BXHJ = this.MessageData.Fd102_S

        return output
    }
}

// Vue组合式API封装
export const useAccountInterestCalculation = () => {
    return {
        AccountInterestCalculation,
        AccountInterestCalculationInput
    }
}