import { AXPWidgetsList } from '@acorex/modules/common';
import { createAllQueryView, AXPEntityCommandScope } from '@acorex/platform/common';
import { entityMasterCrudActions, entityMasterRecordActions } from '@acorex/platform/layout/entity';
import { AXPWidgetsCatalog } from '@acorex/platform/layout/widget-core';
import { RootConfig } from './acorex-modules-workflow-management.mjs';

async function factory() {
    const entityDef = {
        module: RootConfig.module.name,
        name: RootConfig.entities.workflowDefinition.name,
        title: RootConfig.entities.workflowDefinition.title,
        icon: RootConfig.entities.workflowDefinition.icon,
        formats: {
            individual: RootConfig.entities.workflowDefinition.title,
            plural: RootConfig.entities.workflowDefinition.titlePlural,
            displayName: '{{ title || name }}',
            searchResult: {
                title: '{{ title || name }}',
                description: '{{ description }}',
            },
        },
        plugins: [
            { name: 'history' },
            { name: 'lock' },
            { name: 'archive' },
            { name: 'category' },
        ],
        groups: [
            {
                id: 'basicInfo',
                title: '@workflow-management:workflow-definitions.entities.workflow-definition.groups.basic-info',
            },
            {
                id: 'configuration',
                title: '@workflow-management:workflow-definitions.entities.workflow-definition.groups.configuration',
            },
            {
                id: 'metadata',
                title: '@workflow-management:workflow-definitions.entities.workflow-definition.groups.metadata',
            },
            {
                id: 'classification',
                title: '@workflow-management:workflow-definitions.entities.workflow-definition.groups.classification',
            },
        ],
        properties: [
            {
                name: 'id',
                title: 'ID',
                groupId: 'metadata',
                schema: {
                    dataType: 'uuid',
                    visible: false,
                    nullable: false,
                    readonly: true,
                    unique: { enabled: true },
                },
            },
            {
                name: 'name',
                title: '@workflow-management:workflow-definitions.entities.workflow-definition.fields.name.title',
                groupId: 'basicInfo',
                schema: {
                    dataType: 'string',
                    readonly: '{{context.id}}',
                    interface: {
                        type: AXPWidgetsCatalog.text,
                        options: {
                            placeholder: '@workflow-management:workflow-definitions.entities.workflow-definition.fields.name.placeholder',
                        },
                    },
                },
                options: {
                    sort: { enabled: true },
                    filter: { advance: { enabled: true }, inline: { enabled: true } },
                },
                validations: [{ rule: 'required' }, { rule: 'unique' }],
            },
            {
                name: 'title',
                title: '@workflow-management:workflow-definitions.entities.workflow-definition.fields.title.title',
                groupId: 'basicInfo',
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsCatalog.text,
                        options: {
                            placeholder: '@workflow-management:workflow-definitions.entities.workflow-definition.fields.title.placeholder',
                        },
                    },
                },
                options: {
                    sort: { enabled: true },
                    filter: { advance: { enabled: true }, inline: { enabled: true } },
                },
            },
            {
                name: 'description',
                title: '@workflow-management:workflow-definitions.entities.workflow-definition.fields.description.title',
                groupId: 'basicInfo',
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsList.Editors.LargeTextBox,
                        options: {
                            rows: 3,
                            placeholder: '@workflow-management:workflow-definitions.entities.workflow-definition.fields.description.placeholder',
                        },
                    },
                },
            },
            {
                name: 'version',
                title: '@workflow-management:workflow-definitions.entities.workflow-definition.fields.version.title',
                groupId: 'metadata',
                schema: {
                    dataType: 'number',
                    interface: {
                        type: AXPWidgetsCatalog.number,
                    },
                    readonly: true,
                },
                options: {
                    sort: { enabled: true },
                    filter: { advance: { enabled: true } },
                },
            },
            {
                name: 'isLatest',
                title: '@workflow-management:workflow-definitions.entities.workflow-definition.fields.is-latest.title',
                groupId: 'metadata',
                schema: {
                    dataType: 'boolean',
                    interface: {
                        type: AXPWidgetsCatalog.toggle,
                    },
                    readonly: true,
                },
                options: {
                    filter: { inline: { enabled: true } },
                },
            },
            {
                name: 'isPublished',
                title: '@workflow-management:workflow-definitions.entities.workflow-definition.fields.is-published.title',
                groupId: 'configuration',
                schema: {
                    dataType: 'boolean',
                    interface: {
                        type: AXPWidgetsCatalog.toggle,
                    },
                },
                options: {
                    filter: { inline: { enabled: true } },
                },
            },
            {
                name: 'isReadonly',
                title: '@workflow-management:workflow-definitions.entities.workflow-definition.fields.is-readonly.title',
                groupId: 'configuration',
                schema: {
                    dataType: 'boolean',
                    interface: {
                        type: AXPWidgetsCatalog.toggle,
                    },
                },
            },
            {
                name: 'isSystem',
                title: '@workflow-management:workflow-definitions.entities.workflow-definition.fields.is-system.title',
                groupId: 'configuration',
                schema: {
                    dataType: 'boolean',
                    interface: {
                        type: AXPWidgetsCatalog.toggle,
                    },
                    readonly: true,
                },
            },
            {
                name: 'createdAt',
                title: '@workflow-management:workflow-definitions.entities.workflow-definition.fields.created-at.title',
                groupId: 'metadata',
                schema: {
                    dataType: 'date',
                    interface: {
                        type: AXPWidgetsCatalog.dateTime,
                    },
                    readonly: true,
                },
                options: {
                    sort: { enabled: true },
                    filter: { advance: { enabled: true } },
                },
            },
            {
                name: 'bindings',
                title: '@workflow-management:workflow-definitions.entities.workflow-definition.fields.bindings.title',
                groupId: 'configuration',
                schema: {
                    dataType: 'array',
                    interface: {
                        type: AXPWidgetsList.Advanced.CodeEditor,
                        options: {
                            language: 'json',
                            placeholder: '[{ "entityTypes": ["Module.Entity"], "eventTypes": ["OnCreate"], "enabled": true }]',
                        },
                    },
                },
                options: {
                    filter: { advance: { enabled: false } },
                    sort: { enabled: false },
                },
            },
        ],
        relatedEntities: [
            {
                entity: `${RootConfig.module.name}.${RootConfig.entities.workflowInstance.name}`,
                title: '@workflow-management:workflow-definitions.related-entities.workflow-instances.title',
                columns: ['name', 'definitionId', 'status', 'subStatus', 'createdAt'],
                conditions: [
                    {
                        name: 'definitionId',
                        operator: { type: 'equal' },
                        value: '{{context.eval("name")}}',
                    },
                ],
                layout: { type: 'tab-list' },
            },
            {
                entity: `${RootConfig.module.name}.${RootConfig.entities.activityDefinition.name}`,
                title: '@workflow-management:workflow-definitions.related-entities.activity-definitions.title',
                columns: ['name', 'title', 'type', 'executionMode'],
                layout: { type: 'tab-list' },
            },
        ],
        columns: [
            {
                name: 'title',
                title: '@workflow-management:workflow-definitions.entities.workflow-definition.fields.title.title',
                showAs: { type: AXPWidgetsCatalog.text },
            },
            {
                name: 'name',
                title: '@workflow-management:workflow-definitions.entities.workflow-definition.fields.name.title',
                showAs: { type: AXPWidgetsCatalog.text },
            },
            {
                name: 'version',
                title: '@workflow-management:workflow-definitions.entities.workflow-definition.fields.version.title',
                showAs: { type: AXPWidgetsCatalog.number },
                options: { width: '100px' },
            },
            {
                name: 'isLatest',
                title: '@workflow-management:workflow-definitions.entities.workflow-definition.fields.is-latest.title',
                showAs: { type: AXPWidgetsCatalog.toggle, options: { trueText: 'Latest', falseText: '-' } },
                options: { width: '100px' },
            },
            {
                name: 'isPublished',
                title: '@workflow-management:workflow-definitions.entities.workflow-definition.fields.is-published.title',
                showAs: { type: AXPWidgetsCatalog.toggle },
                options: { width: '120px' },
            },
            {
                name: 'createdAt',
                title: '@workflow-management:workflow-definitions.entities.workflow-definition.fields.created-at.title',
                showAs: { type: AXPWidgetsCatalog.dateTime },
                options: { width: '180px' },
            },
        ],
        interfaces: {
            master: {
                create: {
                    sections: [
                        { id: 'basicInfo' },
                        { id: 'configuration' },
                        { id: 'classification' },
                    ],
                    properties: [
                        { name: 'name', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'title', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'description', layout: { positions: { lg: { colSpan: 12 } } } },
                        { name: 'isPublished', layout: { positions: { lg: { colSpan: 4 } } } },
                        { name: 'isReadonly', layout: { positions: { lg: { colSpan: 4 } } } },
                        { name: 'bindings', layout: { positions: { lg: { colSpan: 12 } } } },
                    ],
                },
                update: {
                    sections: [
                        { id: 'basicInfo' },
                        { id: 'configuration' },
                        { id: 'classification' },
                    ],
                    properties: [
                        { name: 'name', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'title', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'description', layout: { positions: { lg: { colSpan: 12 } } } },
                        { name: 'isPublished', layout: { positions: { lg: { colSpan: 4 } } } },
                        { name: 'isReadonly', layout: { positions: { lg: { colSpan: 4 } } } },
                        { name: 'bindings', layout: { positions: { lg: { colSpan: 12 } } } },
                    ],
                },
                single: {
                    title: '{{ title }}',
                    sections: [
                        { id: 'basicInfo', order: 1, layout: { positions: { lg: { colSpan: 12 } } } },
                        { id: 'configuration', order: 2, layout: { positions: { lg: { colSpan: 6 } } } },
                        { id: 'classification', order: 3, layout: { positions: { lg: { colSpan: 6 } } } },
                        { id: 'metadata', order: 4, layout: { positions: { lg: { colSpan: 12 } } } },
                    ],
                    properties: [
                        { name: 'name', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'title', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'description', layout: { positions: { lg: { colSpan: 12 } } } },
                        { name: 'version', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'isLatest', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'isPublished', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'isReadonly', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'isSystem', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'createdAt', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'bindings', layout: { positions: { lg: { colSpan: 12 } } } },
                    ],
                    actions: [...entityMasterRecordActions()],
                },
                list: {
                    actions: [
                        ...entityMasterCrudActions(),
                        {
                            title: '@workflow-management:workflow-definitions.actions.execute.title',
                            name: 'execute-workflow',
                            command: {
                                name: 'WorkflowManagement.WorkflowDefinition:Execute',
                                options: {
                                    workflowId: '{{ context.eval("name") }}',
                                    input: {},
                                },
                            },
                            icon: 'fa-light fa-play',
                            color: 'success',
                            priority: 'primary',
                            type: 'execute',
                            scope: AXPEntityCommandScope.Individual,
                        },
                        {
                            title: '@workflow-management:workflow-definitions.actions.edit-in-studio.title',
                            name: 'edit-in-studio',
                            command: {
                                name: 'WorkflowManagement.WorkflowDefinition:EditInStudio',
                                options: {
                                    workflowName: '{{ context.eval("name") }}',
                                },
                            },
                            icon: 'fa-light fa-code',
                            color: 'primary',
                            priority: 'secondary',
                            type: 'execute',
                            scope: AXPEntityCommandScope.Individual,
                        },
                    ],
                    views: [createAllQueryView({ sorts: [{ name: 'createdAt', dir: 'desc' }] })],
                },
            },
        },
    };
    return entityDef;
}

export { factory };
//# sourceMappingURL=acorex-modules-workflow-management-workflow-definition.entity-nJMBL0qt.mjs.map
