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

async function factory(injector) {
    const dataService = injector.get(AXMOrganizationManagementResponsibilityEntityService);
    const i18n = RootConfig.config.i18n;
    const entityName = 'responsibility';
    const entityDef = {
        module: RootConfig.module.name,
        name: RootConfig.entities.responsibility.name,
        plugins: [
            { name: 'history' },
            { name: 'lock' },
            { name: 'compare' },
            { name: 'category' },
        ],
        title: RootConfig.entities.responsibility.title,
        icon: RootConfig.entities.responsibility.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: 'basic-info',
                title: `@general:terms.interface.basic-info`,
            },
        ],
        properties: [
            {
                name: 'id',
                title: 'ID',
                schema: {
                    dataType: 'uuid',
                    hidden: true,
                    nullable: false,
                    readonly: true,
                    unique: {
                        enabled: true,
                    },
                },
            },
            {
                name: 'title',
                title: `@general:terms.common.title`,
                groupId: 'basic-info',
                options: {
                    sort: {
                        enabled: true,
                    },
                    filter: {
                        advance: {
                            enabled: true,
                        },
                        inline: {
                            enabled: true,
                        },
                    },
                },
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsCatalog.text,
                    },
                },
                validations: [
                    {
                        rule: 'required',
                    },
                ],
            },
            {
                name: 'description',
                title: `@general:terms.common.description`,
                groupId: 'basic-info',
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsCatalog.largeText,
                    },
                },
            },
        ],
        columns: [{ name: 'title' }, { name: 'description' }],
        commands: {
            create: {
                execute: async (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: 'basic-info',
                        },
                    ],
                    properties: [
                        {
                            name: 'title',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 12,
                                        order: 1,
                                    },
                                },
                            },
                        },
                        {
                            name: 'description',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 12,
                                        order: 3,
                                    },
                                },
                            },
                        },
                    ],
                },
                update: {
                    sections: [
                        {
                            id: 'basic-info',
                        },
                    ],
                    properties: [
                        {
                            name: 'title',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 12,
                                        order: 1,
                                    },
                                },
                            },
                        },
                        {
                            name: 'description',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 12,
                                        order: 3,
                                    },
                                },
                            },
                        },
                    ],
                },
                single: {
                    title: '{{title}}',
                    sections: [
                        {
                            id: 'basic-info',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 12,
                                    },
                                },
                            },
                        },
                    ],
                    properties: [
                        {
                            name: 'title',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 12,
                                        order: 1,
                                    },
                                },
                            },
                        },
                        {
                            name: 'description',
                            layout: {
                                positions: {
                                    lg: {
                                        colSpan: 12,
                                        order: 3,
                                    },
                                },
                            },
                        },
                    ],
                    actions: [
                        entityMasterDeleteAction()
                    ],
                },
                list: {
                    actions: [
                        ...entityMasterCrudActions()
                    ],
                    views: [
                        createAllQueryView({
                            sorts: [{ name: 'title', dir: 'asc' }],
                        }),
                    ],
                },
            },
        },
    };
    return entityDef;
}

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