package cn.stylefeng.team.project.modular.filing.factory;

import cn.hutool.core.collection.ListUtil;
import cn.stylefeng.team.form.api.pojo.FormDesignVo;
import cn.stylefeng.team.meta.api.entity.MetaField;
import cn.stylefeng.team.project.api.enums.DataRenderTypeEnum;
import cn.stylefeng.team.view.api.pojo.ViewButton;
import cn.stylefeng.team.view.api.pojo.ViewConfig;
import cn.stylefeng.team.view.modular.factory.ViewConfigFactory;
import cn.stylefeng.team.view.modular.pojo.response.ViewFieldResult;
import com.alibaba.fastjson.JSON;

import java.util.List;

public class AutoViewConfigFactory {

    public static ViewConfig createFormBasedViewConfig(List<MetaField> mainModelFieldList, FormDesignVo formDesignVo) {

        ViewFieldResult formBasedFieldList = ViewConfigFactory.createFormBasedFieldList(mainModelFieldList, ListUtil.of(formDesignVo));

        ViewConfig viewConfig = new ViewConfig();
        viewConfig.setViewColumnFieldList(formBasedFieldList.getViewColumnFieldList());
        viewConfig.setViewSearchFieldList(formBasedFieldList.getViewSearchFieldList());
        viewConfig.setDataRenderType(DataRenderTypeEnum.AUTO.getCode());

        viewConfig.setViewButtonList(JSON.parseArray("""
                [
                        {
                            "buttonId": null,
                            "buttonCode": "add",
                            "buttonIcon": "",
                            "buttonName": "新增",
                            "buttonPlace": null,
                            "buttonVisible": true,
                            "customRouterUrl": "",
                            "buttonPermissionCode": ""
                        },
                        {
                            "buttonId": null,
                            "buttonCode": "edit",
                            "buttonIcon": "",
                            "buttonName": "编辑",
                            "buttonPlace": null,
                            "buttonVisible": true,
                            "customRouterUrl": "",
                            "buttonPermissionCode": ""
                        },
                        {
                            "buttonId": null,
                            "buttonCode": "detail",
                            "buttonIcon": "",
                            "buttonName": "详情",
                            "buttonPlace": null,
                            "buttonVisible": true,
                            "customRouterUrl": "",
                            "buttonPermissionCode": ""
                        },
                        {
                            "buttonId": null,
                            "buttonCode": "delete",
                            "buttonIcon": "",
                            "buttonName": "删除",
                            "buttonPlace": null,
                            "buttonVisible": true,
                            "customRouterUrl": "",
                            "buttonPermissionCode": ""
                        },
                        {
                            "buttonId": null,
                            "buttonCode": "export",
                            "buttonIcon": "",
                            "buttonName": "导出",
                            "buttonPlace": null,
                            "buttonVisible": true,
                            "customRouterUrl": "",
                            "buttonPermissionCode": ""
                        }
                    ]
                """, ViewButton.class));

        return viewConfig;
    }

}
