import { createAllQueryView, AXPEntityQueryType } from '@acorex/platform/common';
import { AXPEntityDefinitionRegistryService, entityMasterCrudActions, entityMasterRecordActions } from '@acorex/platform/layout/entity';
import { AXPWidgetsCatalog } from '@acorex/platform/layout/widget-core';
import { A as AXPReservationManagementReservationStatusTransitionService, R as RootConfig } from './acorex-modules-reservation-management-acorex-modules-reservation-management-C1ehsiff.mjs';

//#region ----   Imports   ----
//#endregion
//#region ----   Entity Factory   ----
async function reservationStatusTransitionFactory(injector) {
    const dataService = injector.get(AXPReservationManagementReservationStatusTransitionService);
    const entityRegistry = injector.get(AXPEntityDefinitionRegistryService);
    const i18n = RootConfig.config.i18n;
    const entityDef = {
        module: RootConfig.module.name,
        name: RootConfig.entities.reservationStatusTransition.name,
        title: RootConfig.entities.reservationStatusTransition.title,
        icon: RootConfig.entities.reservationStatusTransition.icon,
        formats: {
            individual: RootConfig.entities.reservationStatusTransition.title,
            plural: RootConfig.entities.reservationStatusTransition.titlePlural,
            searchResult: {
                title: '{{ title || (fromStatus?.title + " → " + toStatus?.title) }}',
                description: '{{ reservationClass?.title }}',
            },
        },
        groups: [
            {
                id: 'transition-details',
                title: '@reservation-management:reservation-status-transitions.entities.reservation-status-transition.groups.transition-details',
            },
        ],
        plugins: [],
        properties: [
            {
                name: 'id',
                title: '@general:terms.common.id',
                schema: { dataType: 'uuid', visible: false, nullable: false, readonly: true, unique: { enabled: true } },
            },
            {
                name: 'reservationClassId',
                title: '@reservation-management:reservation-status-transitions.entities.reservation-status-transition.fields.reservation-class-id.title',
                groupId: 'transition-details',
                schema: {
                    dataType: 'string',
                    visible: false,
                    interface: {
                        type: AXPWidgetsCatalog.lookup,
                        options: {
                            entity: `${RootConfig.module.name}.${RootConfig.entities.reservationClass.name}`,
                            textField: 'title',
                            valueField: 'id',
                            columns: ['code', 'title'],
                            expose: [
                                { source: 'id', target: 'reservationClass.id' },
                                { source: 'title', target: 'reservationClass.title' },
                                { source: 'code', target: 'reservationClass.code' },
                            ],
                        },
                    },
                },
                options: {
                    sort: { enabled: true },
                    filter: { advance: { enabled: true }, inline: { enabled: true } },
                },
                validations: [{ rule: 'required' }],
            },
            {
                name: 'fromStatusId',
                title: '@reservation-management:reservation-status-transitions.entities.reservation-status-transition.fields.from-status-id.title',
                groupId: 'transition-details',
                schema: {
                    dataType: 'object',
                    interface: {
                        type: AXPWidgetsCatalog.lookup,
                        options: {
                            entity: `${RootConfig.module.name}.${RootConfig.entities.reservationClassStatus.name}`,
                            look: 'select',
                            textField: 'title',
                            valueField: 'id',
                            columns: ['name', 'title', 'color'],
                            expose: [
                                { source: 'id', target: 'fromStatus.id' },
                                { source: 'title', target: 'fromStatus.title' },
                                { source: 'name', target: 'fromStatus.name' },
                            ],
                            filter: {
                                logic: 'and',
                                filters: [
                                    {
                                        field: 'reservationClassId',
                                        operator: { type: 'equal' },
                                        value: '{{ context.eval("reservationClassId.value") }}',
                                    },
                                ],
                            },
                            triggers: [
                                {
                                    event: "{{ events.context('reservationClassId') }}",
                                    //action:"{{console.log(context.eval('reservationClassId'))}}"
                                    action: `{{  widget.refresh() }}`,
                                },
                            ],
                        },
                    },
                },
                options: {
                    sort: { enabled: true },
                    filter: { advance: { enabled: true }, inline: { enabled: true } },
                },
                validations: [{ rule: 'required' }],
            },
            {
                name: 'toStatusId',
                title: '@reservation-management:reservation-status-transitions.entities.reservation-status-transition.fields.to-status-id.title',
                groupId: 'transition-details',
                schema: {
                    dataType: 'object',
                    interface: {
                        type: AXPWidgetsCatalog.lookup,
                        options: {
                            entity: `${RootConfig.module.name}.${RootConfig.entities.reservationClassStatus.name}`,
                            look: 'select',
                            textField: 'title',
                            valueField: 'id',
                            columns: ['name', 'title'],
                            expose: [
                                { source: 'id', target: 'toStatus.id' },
                                { source: 'title', target: 'toStatus.title' },
                                { source: 'name', target: 'toStatus.name' },
                            ],
                            filter: {
                                logic: 'and',
                                filters: [
                                    {
                                        field: 'reservationClassId',
                                        operator: { type: 'equal' },
                                        value: '{{ context.eval("reservationClassId.value") }}',
                                    },
                                ],
                            },
                            triggers: [
                                {
                                    event: "{{ events.context('reservationClassId') }}",
                                    action: "{{console.log(context.eval('reservationClassId'))}}" //action: `{{ !context.eval('reservationClassId.value') ? widget.setValue(null) : widget.refresh() }}`,
                                },
                            ],
                        },
                    },
                },
                options: {
                    sort: { enabled: true },
                    filter: { advance: { enabled: true }, inline: { enabled: true } },
                },
                validations: [{ rule: 'required' }],
            },
        ],
        columns: [
            { name: 'fromStatusId', options: { dataPath: 'fromStatus.title' } },
            { name: 'toStatusId', options: { dataPath: 'toStatus.title' } },
        ],
        commands: {
            create: {
                execute: async (data) => {
                    return { id: await dataService.insertOne(data) };
                },
            },
            update: {
                execute: async (data) => {
                    return await dataService.updateOne(data.id, data);
                },
            },
            delete: {
                execute: async (id) => {
                    return await dataService.deleteOne(id);
                },
            },
        },
        queries: {
            byKey: {
                execute: async (id) => {
                    return await dataService.getOne(id);
                },
                type: AXPEntityQueryType.Single,
            },
            list: {
                execute: async (e) => {
                    return await dataService.query({
                        skip: e.skip,
                        take: e.take,
                        filter: e.filter,
                        sort: e.sort,
                    });
                },
                type: AXPEntityQueryType.List,
            },
        },
        interfaces: {
            master: {
                create: {
                    sections: [{ id: 'transition-details' }],
                    properties: [
                        { name: 'reservationClassId', layout: { positions: { lg: { colSpan: 12 } } } },
                        { name: 'title', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'fromStatusId', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'toStatusId', layout: { positions: { lg: { colSpan: 6 } } } },
                    ],
                },
                update: {
                    sections: [{ id: 'transition-details' }],
                    properties: [
                        { name: 'reservationClassId', layout: { positions: { lg: { colSpan: 12 } } } },
                        { name: 'title', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'fromStatusId', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'toStatusId', layout: { positions: { lg: { colSpan: 6 } } } },
                    ],
                },
                single: {
                    title: '{{ title || (fromStatus?.title + " → " + toStatus?.title) }}',
                    sections: [{ id: 'transition-details' }],
                    properties: [
                        { name: 'reservationClassId', layout: { positions: { lg: { colSpan: 12 } } } },
                        { name: 'title', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'fromStatusId', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'toStatusId', layout: { positions: { lg: { colSpan: 6 } } } },
                    ],
                    actions: [...entityMasterRecordActions()],
                },
                list: {
                    actions: [...entityMasterCrudActions()],
                    views: [
                        createAllQueryView({
                            sorts: [
                                { name: 'fromStatusId', dir: 'asc' },
                                { name: 'toStatusId', dir: 'asc' },
                            ],
                        }),
                    ],
                },
            },
        },
    };
    return entityDef;
}
//#endregion

export { reservationStatusTransitionFactory };
//# sourceMappingURL=acorex-modules-reservation-management-reservation-status-transition.entity-ilzVQIWd.mjs.map
