import { reactive } from 'vue'
import type { PageBase } from './PageBase'
import type { TradeInfoData } from './TradeInfoData'

/**
 * 交易基础信息的访问辅助类
 */
export class TradeInfoHelper {
    private _tradeInfoData: TradeInfoData
    private _page: PageBase

    constructor(page: PageBase) {
        this._page = page
        this._tradeInfoData = TradeInfoData.GetTradeInfo(page)
    }

    /**
     * 获取页面对象
     */
    public get Page(): PageBase {
        return this._page
    }

    /**
     * 柜员前端流水号
     */
    public get SerialNumber(): string {
        return this._tradeInfoData.SerialNumber
    }

    /**
     * 系统前端流水号
     */
    public get SystemSerialNumber(): string {
        return this._tradeInfoData.SystemSerialNumber
    }

    /**
     * 打印票号
     */
    public get PrintNum(): string {
        return this._tradeInfoData.PrintNum
    }

    /**
     * 交易号，指代一个完整的业务流程
     */
    public get TradeCode(): string {
        return this._tradeInfoData.TradeCode
    }

    /**
     * 交易名称，指代一个完整的业务流程
     */
    public get TradeName(): string {
        return this._tradeInfoData.TradeName
    }

    /**
     * 交易截图
     */
    public get TradeScreens(): Map<string, Array<ImageBitmap>> {
        return this._tradeInfoData.TradeScreens
    }
    public set TradeScreens(value: Map<string, Array<ImageBitmap>>) {
        this._tradeInfoData.TradeScreens = value
    }

    /**
     * 主交易提交代码
     */
    public get MainCode(): string {
        return this._tradeInfoData.TradeBus.get('MainCode') || ''
    }
    public set MainCode(value: string) {
        this._tradeInfoData.TradeBus.set('MainCode', value)
    }
}

// Vue组件封装
export const useTradeInfo = (page: PageBase) => {
    return reactive(new TradeInfoHelper(page))
}