import { UIActionContext } from "@/logic/ui-logic";
/**
 * 自定义表格数据加载
 *
 * @export
 * @class GridViewLoadUILogicBase
 */
export default class GridViewLoadUILogicBase {

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

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

    /**
     * 逻辑参数
     *
     * @protected
     * @type {any[]}
     * @memberof GridViewLoadUILogicBase
     */
    protected logicParams: any[] = [
        {
            name: '当前视图参数',
            codeName: 'viewParam',
            activeContainerParam: false,
            activeCtrlParam: false,
            activeViewParam: false,
            appGlobalParam: false,
            applicationParam: false,
            ctrlParam: false,
            default: false,
            entityParam: false,
            entityListParam: false,
            entityPageParam: false,
            filterParam: false,
            navContextParam: false,
            simpleParam: false,
            simpleListParam: false,
            routeViewSessionParam: false,
            viewNavDataParam: true,
            viewSessionParam: false,
            lastReturnParam: false
        },
        {
            name: '当前视图对象',
            codeName: 'view',
            activeContainerParam: false,
            activeCtrlParam: false,
            activeViewParam: true,
            appGlobalParam: false,
            applicationParam: false,
            ctrlParam: false,
            default: false,
            entityParam: false,
            entityListParam: false,
            entityPageParam: false,
            filterParam: false,
            navContextParam: false,
            simpleParam: false,
            simpleListParam: false,
            routeViewSessionParam: false,
            viewNavDataParam: false,
            viewSessionParam: false,
            lastReturnParam: false
        },
        {
            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
        },
        {
            name: '当前表格',
            codeName: 'grid',
            activeContainerParam: false,
            activeCtrlParam: false,
            activeViewParam: false,
            appGlobalParam: false,
            applicationParam: false,
            ctrlParam: true,
            default: false,
            entityParam: false,
            entityListParam: false,
            entityPageParam: false,
            filterParam: false,
            navContextParam: false,
            simpleParam: false,
            simpleListParam: false,
            routeViewSessionParam: false,
            viewNavDataParam: false,
            viewSessionParam: false,
            lastReturnParam: false
        },
        {
            name: '当前搜索表单',
            codeName: 'searchForm',
            activeContainerParam: false,
            activeCtrlParam: false,
            activeViewParam: false,
            appGlobalParam: false,
            applicationParam: false,
            ctrlParam: true,
            default: false,
            entityParam: false,
            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 GridViewLoadUILogicBase
     */
    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 GridViewLoadUILogicBase
     */
    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_bindparam1_node(actionContext);
    }
    /**
     * 处理参数
     *
     * @param {UIActionContext} actionContext 界面逻辑上下文
     */
    protected async execute_bindparam1_node(actionContext: UIActionContext) {
        //  自定义表格数据加载
    //  TODO 等待补充
    console.log('已完成执行 绑定当前搜索表单 节点');
    await this.execute_viewctrlinvoke1_node(actionContext);
    }
    /**
     * 处理参数
     *
     * @param {UIActionContext} actionContext 界面逻辑上下文
     */
    protected async execute_viewctrlinvoke1_node(actionContext: UIActionContext) {
        //  自定义表格数据加载
    //  TODO 等待补充
    console.log('已完成执行 视图部件调用 节点');
    await this.execute_viewctrlinvoke2_node(actionContext);
    }
    /**
     * 处理参数
     *
     * @param {UIActionContext} actionContext 界面逻辑上下文
     */
    protected async execute_end1_node(actionContext: UIActionContext) {
        //  自定义表格数据加载
    //  TODO 等待补充
    console.log('已完成执行 结束 节点');
    }
    /**
     * 处理参数
     *
     * @param {UIActionContext} actionContext 界面逻辑上下文
     */
    protected async execute_viewctrlinvoke2_node(actionContext: UIActionContext) {
        //  自定义表格数据加载
    //  TODO 等待补充
    console.log('已完成执行 视图部件调用 节点');
    await this.execute_end1_node(actionContext);
    }

}