import { createAllQueryView } 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.workflowInstance.name,
        title: RootConfig.entities.workflowInstance.title,
        icon: RootConfig.entities.workflowInstance.icon,
        formats: {
            individual: RootConfig.entities.workflowInstance.title,
            plural: RootConfig.entities.workflowInstance.titlePlural,
            displayName: '{{ name || definitionId }}',
            searchResult: {
                title: '{{ name || definitionId }}',
                description: '{{ status }} - {{ subStatus }}',
            },
        },
        plugins: [{ name: 'history' }],
        groups: [
            {
                id: 'basicInfo',
                title: '@workflow-management:workflow-instances.entities.workflow-instance.groups.basic-info',
            },
            {
                id: 'status',
                title: '@workflow-management:workflow-instances.entities.workflow-instance.groups.status',
            },
            {
                id: 'metadata',
                title: '@workflow-management:workflow-instances.entities.workflow-instance.groups.metadata',
            },
        ],
        properties: [
            {
                name: 'id',
                title: 'ID',
                groupId: 'metadata',
                schema: {
                    dataType: 'uuid',
                    visible: false,
                    nullable: false,
                    readonly: true,
                    unique: { enabled: true },
                },
            },
            {
                name: 'definitionId',
                title: '@workflow-management:workflow-instances.entities.workflow-instance.fields.definition-id.title',
                groupId: 'basicInfo',
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsCatalog.text,
                        options: {
                            placeholder: '@workflow-management:workflow-instances.entities.workflow-instance.fields.definition-id.placeholder',
                        },
                    },
                },
                options: {
                    sort: { enabled: true },
                    filter: { advance: { enabled: true }, inline: { enabled: true } },
                },
                validations: [{ rule: 'required' }],
            },
            {
                name: 'name',
                title: '@workflow-management:workflow-instances.entities.workflow-instance.fields.name.title',
                groupId: 'basicInfo',
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsCatalog.text,
                        options: {
                            placeholder: '@workflow-management:workflow-instances.entities.workflow-instance.fields.name.placeholder',
                        },
                    },
                },
                options: {
                    sort: { enabled: true },
                    filter: { advance: { enabled: true }, inline: { enabled: true } },
                },
            },
            {
                name: 'status',
                title: '@workflow-management:workflow-instances.entities.workflow-instance.fields.status.title',
                groupId: 'status',
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsCatalog.select,
                        options: {
                            valueField: 'value',
                            textField: 'text',
                            dataSource: [
                                { value: 'Running', text: '@workflow-management:workflow-instances.states.running' },
                                { value: 'Finished', text: '@workflow-management:workflow-instances.states.finished' },
                            ],
                        },
                    },
                    readonly: true,
                },
                options: {
                    sort: { enabled: true },
                    filter: { advance: { enabled: true }, inline: { enabled: true } },
                },
            },
            {
                name: 'subStatus',
                title: '@workflow-management:workflow-instances.entities.workflow-instance.fields.sub-status.title',
                groupId: 'status',
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsCatalog.select,
                        options: {
                            valueField: 'value',
                            textField: 'text',
                            dataSource: [
                                { value: 'Pending', text: '@workflow-management:workflow-instances.states.pending' },
                                { value: 'Executing', text: '@workflow-management:workflow-instances.states.executing' },
                                { value: 'Suspended', text: '@workflow-management:workflow-instances.states.suspended' },
                                { value: 'Finished', text: '@workflow-management:workflow-instances.states.finished' },
                                { value: 'Cancelled', text: '@workflow-management:workflow-instances.states.cancelled' },
                                { value: 'Faulted', text: '@workflow-management:workflow-instances.states.faulted' },
                            ],
                        },
                    },
                    readonly: true,
                },
                options: {
                    sort: { enabled: true },
                    filter: { advance: { enabled: true }, inline: { enabled: true } },
                },
            },
            {
                name: 'correlationId',
                title: '@workflow-management:workflow-instances.entities.workflow-instance.fields.correlation-id.title',
                groupId: 'basicInfo',
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsCatalog.text,
                        options: {
                            placeholder: '@workflow-management:workflow-instances.entities.workflow-instance.fields.correlation-id.placeholder',
                        },
                    },
                },
                options: {
                    sort: { enabled: true },
                    filter: { advance: { enabled: true }, inline: { enabled: true } },
                },
            },
            {
                name: 'version',
                title: '@workflow-management:workflow-instances.entities.workflow-instance.fields.version.title',
                groupId: 'metadata',
                schema: {
                    dataType: 'number',
                    interface: {
                        type: AXPWidgetsCatalog.number,
                    },
                    readonly: true,
                },
                options: {
                    sort: { enabled: true },
                    filter: { advance: { enabled: true } },
                },
            },
            {
                name: 'incidentCount',
                title: '@workflow-management:workflow-instances.entities.workflow-instance.fields.incident-count.title',
                groupId: 'status',
                schema: {
                    dataType: 'number',
                    interface: {
                        type: AXPWidgetsCatalog.number,
                    },
                    readonly: true,
                },
                options: {
                    sort: { enabled: true },
                    filter: { advance: { enabled: true } },
                },
            },
            {
                name: 'createdAt',
                title: '@workflow-management:workflow-instances.entities.workflow-instance.fields.created-at.title',
                groupId: 'metadata',
                schema: {
                    dataType: 'date',
                    interface: {
                        type: AXPWidgetsCatalog.dateTime,
                    },
                    readonly: true,
                },
                options: {
                    sort: { enabled: true },
                    filter: { advance: { enabled: true } },
                },
            },
            {
                name: 'updatedAt',
                title: '@workflow-management:workflow-instances.entities.workflow-instance.fields.updated-at.title',
                groupId: 'metadata',
                schema: {
                    dataType: 'date',
                    interface: {
                        type: AXPWidgetsCatalog.dateTime,
                    },
                    readonly: true,
                },
                options: {
                    sort: { enabled: true },
                    filter: { advance: { enabled: true } },
                },
            },
            {
                name: 'finishedAt',
                title: '@workflow-management:workflow-instances.entities.workflow-instance.fields.finished-at.title',
                groupId: 'metadata',
                schema: {
                    dataType: 'date',
                    interface: {
                        type: AXPWidgetsCatalog.dateTime,
                    },
                    readonly: true,
                },
                options: {
                    sort: { enabled: true },
                    filter: { advance: { enabled: true } },
                },
            },
        ],
        columns: [
            {
                name: 'definitionId',
                title: '@workflow-management:workflow-instances.entities.workflow-instance.fields.definition-id.title',
                showAs: { type: AXPWidgetsCatalog.text },
            },
            {
                name: 'name',
                title: '@workflow-management:workflow-instances.entities.workflow-instance.fields.name.title',
                showAs: { type: AXPWidgetsCatalog.text },
            },
            {
                name: 'status',
                title: '@workflow-management:workflow-instances.entities.workflow-instance.fields.status.title',
                showAs: { type: AXPWidgetsCatalog.text },
                options: { width: '120px' },
            },
            {
                name: 'subStatus',
                title: '@workflow-management:workflow-instances.entities.workflow-instance.fields.sub-status.title',
                showAs: { type: AXPWidgetsCatalog.text },
                options: { width: '140px' },
            },
            {
                name: 'incidentCount',
                title: '@workflow-management:workflow-instances.entities.workflow-instance.fields.incident-count.title',
                showAs: { type: AXPWidgetsCatalog.number },
                options: { width: '100px' },
            },
            {
                name: 'createdAt',
                title: '@workflow-management:workflow-instances.entities.workflow-instance.fields.created-at.title',
                showAs: { type: AXPWidgetsCatalog.dateTime },
                options: { width: '180px' },
            },
            {
                name: 'finishedAt',
                title: '@workflow-management:workflow-instances.entities.workflow-instance.fields.finished-at.title',
                showAs: { type: AXPWidgetsCatalog.dateTime },
                options: { width: '180px' },
            },
        ],
        interfaces: {
            master: {
                single: {
                    title: '{{ name || definitionId }}',
                    sections: [
                        { id: 'basicInfo', order: 1, layout: { positions: { lg: { colSpan: 12 } } } },
                        { id: 'status', order: 2, layout: { positions: { lg: { colSpan: 6 } } } },
                        { id: 'metadata', order: 3, layout: { positions: { lg: { colSpan: 6 } } } },
                    ],
                    properties: [
                        { name: 'definitionId', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'name', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'correlationId', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'version', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'status', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'subStatus', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'incidentCount', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'createdAt', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'updatedAt', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'finishedAt', layout: { positions: { lg: { colSpan: 6 } } } },
                    ],
                    actions: [...entityMasterRecordActions()],
                },
                list: {
                    actions: [...entityMasterCrudActions()],
                    views: [createAllQueryView({ sorts: [{ name: 'createdAt', dir: 'desc' }] })],
                },
            },
        },
    };
    return entityDef;
}

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