import { UIActionContext } from "@/logic/ui-logic";
/**
 * 打开语雀文档
 *
 * @export
 * @class OpenYuQueUILogicBase
 */
export default class OpenYuQueUILogicBase {

    /**
     * Creates an instance of  OpenYuQueBase.
     * 
     * @param {*} [opts={}]
     * @memberof OpenYuQueUILogicBase
     */
    constructor(opts: any = {}) { }

    /**
     * 开始节点
     *
     * @protected
     * @type {string}
     * @memberof OpenYuQueUILogicBase
     */
    protected readonly startLogicNode: string = 'Begin';

    /**
     * 逻辑参数
     *
     * @protected
     * @type {any[]}
     * @memberof OpenYuQueUILogicBase
     */
    protected logicParams: any[] = [
        {
            name: '传入变量',
            codeName: 'Default',
            activeContainerParam: false,
            activeCtrlParam: false,
            activeViewParam: false,
            appGlobalParam: false,
            applicationParam: false,
            ctrlParam: false,
            default: true,
            entityParam: true,
            entityListParam: false,
            entityPageParam: false,
            filterParam: false,
            navContextParam: false,
            simpleParam: false,
            simpleListParam: false,
            routeViewSessionParam: false,
            viewNavDataParam: false,
            viewSessionParam: false,
            lastReturnParam: false
        },
    ];

    /**
     * 执行前
     *
     * @param {*} args
     * @param {*} [context={}]
     * @param {*} [params={}]
     * @param {*} [$event]
     * @param {*} [xData]
     * @param {*} [actioncontext]
     * @param {string} [srfParentDeName]
     * @return {*} 
     * @memberof OpenYuQueUILogicBase
     */
    public beforeExecute(args: any, context: any = {}, params: any = {},
        $event?: any, xData?: any, actioncontext?: any, srfParentDeName?: string) {
        return new UIActionContext(this.logicParams, args, context, params, $event, xData, actioncontext, srfParentDeName)
    }

    /**
     * 执行
     *
     * @param {any[]} args
     * @param {*} [context={}]
     * @param {*} [params={}]
     * @param {*} [$event]
     * @param {*} [xData]
     * @param {*} [actionContext]
     * @param {string} [srfParentDeName]
     * @memberof OpenYuQueUILogicBase
     */
    async execute(args: any[], context:any = {} ,params: any = {}, $event?: any, xData?: any, actioncontext?: any, srfParentDeName?: string) {
        try {
            const actionContext = this.beforeExecute(args, context, params, $event, xData, actioncontext, srfParentDeName);
            await this.execute_begin_node(actionContext);
            return actionContext.getResult();
        } catch (error: any) {
            throw new Error(`${error && error.message ? error.message : '发生未知错误！'}`);
        }
    }

    /**
     * 处理参数
     *
     * @param {UIActionContext} actionContext 界面逻辑上下文
     */
    protected async execute_begin_node(actionContext: UIActionContext) {
        //  打开语雀文档
    actionContext.setResult(actionContext.defaultParam.getReal());
    console.log('已完成执行 开始 节点');
    await this.execute_deuiaction1_node(actionContext);
    }
    /**
     * 处理参数
     *
     * @param {UIActionContext} actionContext 界面逻辑上下文
     */
    protected async execute_end1_node(actionContext: UIActionContext) {
        //  打开语雀文档
    //  TODO 等待补充
    console.log('已完成执行 结束 节点');
    }
    /**
     * 处理参数
     *
     * @param {UIActionContext} actionContext 界面逻辑上下文
     */
    protected async execute_deuiaction1_node(actionContext: UIActionContext) {
        //  打开语雀文档
    //  TODO 等待补充
    console.log('已完成执行 界面行为 节点');
    await this.execute_end1_node(actionContext);
    }

}