package cc.smtweb.system.bpm.web.engine.model.listcard.lclc1;

import cc.smtweb.framework.core.annotation.SwBody;
import cc.smtweb.framework.core.annotation.SwService;
import cc.smtweb.framework.core.common.R;
import cc.smtweb.framework.core.common.SwMap;
import cc.smtweb.framework.core.mvc.service.AbstractHandler;
import cc.smtweb.framework.core.session.UserSession;
import cc.smtweb.system.bpm.web.engine.model.common.*;

/**
 * @Author:lip
 * @Date : 2022/9/2 11:34
 * 模型LC_LC_1（左列表-右列表（含编辑弹窗、左列表可编辑）） 服务类
 */
@SwService
public class LCLC1Service extends ModelService {
    public final static String TYPE_MODEL_LEFT_LIST = "modelLList";
    public final static String TYPE_MODEL_LEFT_LOAD = "modelLLoad";
    public final static String TYPE_MODEL_LEFT_SAVE = "modelLSave";
    public final static String TYPE_MODEL_LEFT_DEL = "modelLDel";

    @Override
    public AbstractHandler createHandler(String type) {
        switch (type) {
            case TYPE_MODEL_LEFT_LIST:
                return new ModelListHandler(LCLC1Config.dsLList);
            case TYPE_MODEL_LEFT_LOAD:
                return new ModelLoadHandler<>(LCLC1Config.dsLCard);
            case TYPE_MODEL_LEFT_SAVE:
                return new ModelSaveHandler<>(LCLC1Config.dsLCard);
            case TYPE_MODEL_LEFT_DEL:
                return new ModelDelHandler(LCLC1Config.dsLCard);
        }
        return super.createHandler(type);
    }

    /**
     * 左表保存
     * @param params
     * @param us
     * @return
     */
    public R modelLSave(@SwBody SwMap params, UserSession us) {
        return pageHandler(params, us, TYPE_MODEL_LEFT_SAVE, handler -> ((ModelSaveHandler) handler).save());
    }

    /**
     * 左表编辑
     * @param params
     * @param us
     * @return
     */
    public R modelLLoad(@SwBody SwMap params, UserSession us) {
        return pageHandler(params, us, TYPE_MODEL_LEFT_LOAD, handler -> ((ModelLoadHandler) handler).load());
    }

    /**
     * 左表新增初始化
     * @param params
     * @param us
     * @return
     */
    public R modelLAdd(@SwBody SwMap params, UserSession us) {
        return pageHandler(params, us, TYPE_MODEL_LEFT_LOAD, handler -> ((ModelLoadHandler) handler).add());
    }

    /**
     * 左表删除
     * @param params
     * @param us
     * @return
     */
    public R modelLDel(@SwBody SwMap params, UserSession us) {
        return pageHandler(params, us, TYPE_MODEL_LEFT_DEL, handler -> ((ModelDelHandler) handler).del());
    }

    /**
     * 左表列表数据
     * @param params
     * @param us
     * @return
     */
    public R modelLList(@SwBody SwMap params, UserSession us) {
        return pageHandler(params, us, TYPE_MODEL_LEFT_LIST, handler -> ((ModelListHandler) handler).data());
    }

    /**
     * 左表列表总记录数及合计栏
     * @param params
     * @param us
     * @return
     */
    public R modelLListTotal(@SwBody SwMap params, UserSession us) {
        return pageHandler(params, us, TYPE_MODEL_LEFT_LIST, handler -> ((ModelListHandler) handler).getTotal());
    }
}
