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

//#region ----   Imports   ----
//#endregion
//#region ----   Entity Factory   ----
async function reservationClassStatusFactory(injector) {
    const dataService = injector.get(AXPReservationManagementReservationClassStatusService);
    const i18n = RootConfig.config.i18n;
    const entityDef = {
        module: RootConfig.module.name,
        name: RootConfig.entities.reservationClassStatus.name,
        title: RootConfig.entities.reservationClassStatus.title,
        icon: RootConfig.entities.reservationClassStatus.icon,
        formats: {
            individual: RootConfig.entities.reservationClassStatus.title,
            plural: RootConfig.entities.reservationClassStatus.titlePlural,
            searchResult: {
                title: '{{ reservationStatus.title }}',
                description: '{{ reservationClass.title }}',
            },
        },
        groups: [
            {
                id: 'basic-information',
                title: '@reservation-management:reservation-class-statuses.entities.reservation-class-status.groups.basic-information',
            },
            {
                id: 'status-settings',
                title: '@reservation-management:reservation-class-statuses.entities.reservation-class-status.groups.status-settings',
            },
        ],
        properties: [
            {
                name: 'id',
                title: '@general:terms.common.id',
                schema: { dataType: 'uuid', visible: false, nullable: false, readonly: true },
            },
            {
                name: 'reservationClassId',
                title: '@reservation-management:reservation-class-statuses.entities.reservation-class-status.fields.reservation-class-id.title',
                groupId: 'basic-information',
                schema: {
                    dataType: 'string',
                    visible: false,
                    interface: {
                        type: AXPWidgetsCatalog.lookup,
                        options: {
                            entity: `${RootConfig.module.name}.${RootConfig.entities.reservationClass.name}`,
                            textField: 'title',
                            valueField: 'id',
                            columns: ['name', 'title'],
                            readonly: true,
                            expose: [
                                { source: 'id', target: 'reservationClass.id' },
                                { source: 'title', target: 'reservationClass.title' },
                                { source: 'name', target: 'reservationClass.name' },
                            ],
                        },
                    },
                },
                options: {
                    sort: { enabled: true },
                    filter: { advance: { enabled: true }, inline: { enabled: true } },
                },
                validations: [{ rule: 'required' }],
            },
            {
                name: 'reservationStatusId',
                title: '@reservation-management:reservation-class-statuses.entities.reservation-class-status.fields.reservation-status-id.title',
                groupId: 'basic-information',
                schema: {
                    dataType: 'object',
                    interface: {
                        type: AXPWidgetsCatalog.lookup,
                        options: {
                            entity: `${RootConfig.module.name}.${RootConfig.entities.reservationStatus.name}`,
                            look: 'select',
                            textField: 'title',
                            valueField: 'id',
                            columns: ['name', 'title', 'color', 'icon'],
                            expose: [
                                { source: 'id', target: 'reservationStatus.id' },
                                { source: 'title', target: 'reservationStatus.title' },
                                { source: 'name', target: 'reservationStatus.name' },
                                { source: 'color', target: 'reservationStatus.color' },
                                { source: 'icon', target: 'reservationStatus.icon' },
                            ],
                        },
                    },
                },
                options: {
                    sort: { enabled: true },
                    filter: { advance: { enabled: true }, inline: { enabled: true } },
                },
                validations: [{ rule: 'required' }],
            },
            {
                name: 'order',
                title: '@reservation-management:reservation-class-statuses.entities.reservation-class-status.fields.order.title',
                groupId: 'status-settings',
                schema: {
                    dataType: 'number',
                    interface: {
                        type: AXPWidgetsList.Editors.NumberBox,
                        options: {
                            minValue: 0,
                            maxvalue: 10,
                            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 } },
                },
            },
            {
                name: 'isInitial',
                title: '@reservation-management:reservation-class-statuses.entities.reservation-class-status.fields.is-initial.title',
                groupId: 'status-settings',
                schema: {
                    dataType: 'boolean',
                    interface: {
                        type: AXPWidgetsList.Editors.ToggleSwitch,
                        options: {},
                    },
                },
                options: {
                    sort: { enabled: true },
                    filter: { advance: { enabled: true }, inline: { enabled: true } },
                },
            },
            {
                name: 'isFinal',
                title: '@reservation-management:reservation-class-statuses.entities.reservation-class-status.fields.is-final.title',
                groupId: 'status-settings',
                schema: {
                    dataType: 'boolean',
                    interface: {
                        type: AXPWidgetsList.Editors.ToggleSwitch,
                        options: {},
                    },
                },
                options: {
                    sort: { enabled: true },
                    filter: { advance: { enabled: true }, inline: { enabled: true } },
                },
            },
        ],
        columns: [
            { name: 'reservationStatusId', options: { dataPath: 'reservationStatus' } },
            { name: 'order' },
            { name: 'isInitial' },
            { name: 'isFinal' },
        ],
        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: 'basic-information', order: 1 },
                        { id: 'status-settings', order: 2 },
                    ],
                    properties: [
                        { name: 'reservationClassId', layout: { positions: { lg: { colSpan: 12 } } } },
                        { name: 'reservationStatusId', layout: { positions: { lg: { colSpan: 12 } } } },
                        { name: 'order', layout: { positions: { lg: { colSpan: 4 } } } },
                        { name: 'isInitial', layout: { positions: { lg: { colSpan: 4 } } } },
                        { name: 'isFinal', layout: { positions: { lg: { colSpan: 4 } } } },
                    ],
                },
                update: {
                    sections: [
                        { id: 'basic-information', order: 1 },
                        { id: 'status-settings', order: 2 },
                    ],
                    properties: [
                        { name: 'reservationClassId', layout: { positions: { lg: { colSpan: 12 } } } },
                        { name: 'reservationStatusId', layout: { positions: { lg: { colSpan: 12 } } } },
                        { name: 'order', layout: { positions: { lg: { colSpan: 4 } } } },
                        { name: 'isInitial', layout: { positions: { lg: { colSpan: 4 } } } },
                        { name: 'isFinal', layout: { positions: { lg: { colSpan: 4 } } } },
                    ],
                },
                single: {
                    title: '{{ reservationStatus.title }}',
                    sections: [
                        { id: 'basic-information', order: 1 },
                        { id: 'status-settings', order: 2 },
                    ],
                    properties: [
                        { name: 'reservationClassId', layout: { positions: { lg: { colSpan: 12 } } } },
                        { name: 'reservationStatusId', layout: { positions: { lg: { colSpan: 12 } } } },
                        { name: 'order', layout: { positions: { lg: { colSpan: 4 } } } },
                        { name: 'isInitial', layout: { positions: { lg: { colSpan: 4 } } } },
                        { name: 'isFinal', layout: { positions: { lg: { colSpan: 4 } } } },
                    ],
                    actions: [...entityMasterRecordActions()],
                },
                list: {
                    actions: [...entityMasterCrudActions()],
                    views: [
                        createAllQueryView({
                            sorts: [
                                { name: 'order', dir: 'asc' },
                            ],
                        }),
                    ],
                },
            },
        },
    };
    return entityDef;
}
//#endregion

export { reservationClassStatusFactory };
//# sourceMappingURL=acorex-modules-reservation-management-reservation-class-status.entity-DrGJ-Adz.mjs.map
