import { createAllQueryView, AXPEntityCommandScope, AXPEntityQueryType } from '@acorex/platform/common';
import { AXPWidgetsCatalog } from '@acorex/platform/layout/widget-core';
import { AXMOrganizationManagementChartEntityService, RootConfig } from './acorex-modules-organization-management.mjs';
import { entityMasterCrudActions, entityMasterDeleteAction } from '@acorex/platform/layout/entity';

async function factory(injector) {
    const dataService = injector.get(AXMOrganizationManagementChartEntityService);
    const i18n = RootConfig.config.i18n;
    const entityName = 'chart';
    const entityDef = {
        module: RootConfig.module.name,
        name: RootConfig.entities.chart.name,
        plugins: [
            { name: 'history' },
            { name: 'lock' },
            { name: 'compare' },
        ],
        title: RootConfig.entities.chart.title,
        icon: RootConfig.entities.chart.icon,
        formats: {
            individual: `t("${entityName}.individual-title", { scope: "${i18n}" })`,
            plural: `t("${entityName}.plural-title", { scope: "${i18n}" })`,
            searchResult: {
                title: '{{ title }}',
                description: RootConfig.module.title,
            },
        },
        relatedEntities: [],
        groups: [
            {
                id: 'section',
                title: `t("${entityName}.individual-title", { scope: "${i18n}" })`,
            },
        ],
        properties: [
            {
                name: 'name',
                title: `t("${entityName}.name", { scope: "${i18n}" })`,
                groupId: 'section',
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsCatalog.text,
                    },
                },
                validations: [
                    {
                        rule: 'required',
                    },
                ],
            },
            {
                name: 'version',
                title: `t("${entityName}.version", { scope: "${i18n}" })`,
                groupId: 'section',
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsCatalog.text,
                    },
                },
            },
            {
                name: 'structure',
                title: `t("${entityName}.structure", { scope: "${i18n}" })`,
                groupId: 'section',
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsCatalog.text,
                    },
                    defaultValue: '',
                },
            },
        ],
        columns: [{ name: 'name' }, { name: 'version' }],
        commands: {
            create: {
                execute: async (data) => {
                    console.log(data);
                    const res = await dataService.insertOne(data);
                    return { id: res };
                },
            },
            delete: {
                execute: async (id) => {
                    return await dataService.deleteOne(id);
                },
            },
            update: {
                execute: async (data) => {
                    return await dataService.updateOne(data.id, data);
                },
            },
        },
        queries: {
            byKey: {
                execute: async (id) => {
                    return await dataService.getOne(id);
                },
                type: AXPEntityQueryType.Single,
            },
            list: {
                execute: async (e) => {
                    return await dataService.query(e);
                },
                type: AXPEntityQueryType.List,
            },
        },
        interfaces: {
            master: {
                create: {
                    sections: [
                        {
                            id: 'section',
                        },
                    ],
                    properties: [
                        {
                            name: 'name',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                    },
                                },
                            },
                        },
                        {
                            name: 'version',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                    },
                                },
                            },
                        },
                    ],
                },
                update: {
                    sections: [
                        {
                            id: 'section',
                        },
                    ],
                    properties: [
                        {
                            name: 'name',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                    },
                                },
                            },
                        },
                        {
                            name: 'version',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                    },
                                },
                            },
                        },
                    ],
                },
                single: {
                    title: '{{name}}',
                    sections: [
                        {
                            id: 'section',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 12,
                                    },
                                },
                            },
                        },
                    ],
                    properties: [
                        {
                            name: 'name',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                    },
                                },
                            },
                        },
                        {
                            name: 'version',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 6,
                                    },
                                },
                            },
                        },
                    ],
                    actions: [
                        entityMasterDeleteAction()
                    ],
                },
                list: {
                    actions: [
                        ...entityMasterCrudActions(),
                        {
                            title: `t("${entityName}.view-chart", { scope: "${i18n}" })`,
                            command: 'view-chart',
                            priority: 'secondary',
                            type: 'view',
                            scope: AXPEntityCommandScope.Individual,
                        },
                    ],
                    views: [createAllQueryView({ sorts: [{ name: 'name', dir: 'asc' }] })],
                },
            },
        },
    };
    return entityDef;
}

export { factory };
//# sourceMappingURL=acorex-modules-organization-management-chart.entity-DUurUVX-.mjs.map
