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

//#region ----   Imports   ----
//#endregion
//#region ----   Entity Factory   ----
async function reservationResourceTypeFactory(injector) {
    const dataService = injector.get(AXPReservationManagementReservationResourceTypeService);
    const i18n = RootConfig.config.i18n;
    const entityDef = {
        module: RootConfig.module.name,
        name: RootConfig.entities.reservationResourceType.name,
        title: RootConfig.entities.reservationResourceType.title,
        icon: RootConfig.entities.reservationResourceType.icon,
        formats: {
            individual: RootConfig.entities.reservationResourceType.title,
            plural: RootConfig.entities.reservationResourceType.titlePlural,
            searchResult: {
                title: '{{ title }}',
                description: '{{ entity }}',
            },
        },
        groups: [
            {
                id: 'basic-information',
                title: '@reservation-management:reservation-resource-types.entities.reservation-resource-type.groups.basic-information',
            },
        ],
        properties: [
            {
                name: 'id',
                title: '@general:terms.common.id',
                schema: { dataType: 'uuid', visible: false, nullable: false, readonly: true, unique: { enabled: true } },
            },
            {
                name: 'title',
                title: '@reservation-management:reservation-resource-types.entities.reservation-resource-type.fields.title.title',
                groupId: 'basic-information',
                schema: {
                    dataType: 'string',
                    interface: {
                        type: AXPWidgetsList.Editors.TextBox,
                        options: {
                            placeholder: '@reservation-management:reservation-resource-types.entities.reservation-resource-type.fields.title.placeholder',
                        },
                    },
                },
                options: {
                    sort: { enabled: true },
                    filter: { advance: { enabled: true }, inline: { enabled: true } },
                },
                validations: [{ rule: 'required' }],
            },
            {
                name: 'entityId',
                title: '@reservation-management:reservation-resource-types.entities.reservation-resource-type.fields.entity-id.title',
                groupId: 'basic-information',
                schema: {
                    dataType: 'object',
                    interface: {
                        type: AXPWidgetsList.Editors.SelectBox,
                        options: {
                            valueField: 'entity',
                            textField: 'title',
                            allowSearch: true,
                            dataSource: 'entities'
                        },
                    }
                },
                validations: [{ rule: 'required' }],
            },
            {
                name: 'reservationClassId',
                title: '@reservation-management:reservation-resource-types.entities.reservation-resource-type.fields.reservation-class-id.title',
                groupId: 'basic-information',
                schema: {
                    dataType: 'string',
                    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' },
                            ],
                        },
                    },
                },
                options: {
                    sort: { enabled: true },
                    filter: { advance: { enabled: true }, inline: { enabled: true } },
                },
                validations: [{ rule: 'required' }],
            },
        ],
        columns: [{ name: 'title' },
            { name: 'entityId' },
            { name: 'reservationClassId', options: { dataPath: 'reservationClass' } }],
        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' }],
                    properties: [
                        { name: 'title', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'entityId', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'reservationClassId', layout: { positions: { lg: { colSpan: 6 } } } },
                    ],
                },
                update: {
                    sections: [{ id: 'basic-information' }],
                    properties: [
                        { name: 'title', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'entityId', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'reservationClassId', layout: { positions: { lg: { colSpan: 6 } } } },
                    ],
                },
                single: {
                    title: '{{ title }}',
                    sections: [{ id: 'basic-information' }],
                    properties: [
                        { name: 'title', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'entityId', layout: { positions: { lg: { colSpan: 6 } } } },
                        { name: 'reservationClassId', layout: { positions: { lg: { colSpan: 6 } } } },
                    ],
                },
                list: {
                    actions: [...entityMasterCrudActions()],
                    views: [
                        createAllQueryView({
                            sorts: [{ name: 'title', dir: 'asc' }],
                        }),
                    ],
                },
            },
        },
    };
    return entityDef;
}
//#endregion

export { reservationResourceTypeFactory };
//# sourceMappingURL=acorex-modules-reservation-management-reservation-resource-type.entity-3ySsMmeQ.mjs.map
