import { AXDataSource } from '@acorex/cdk/common';
import { AXPEntityService } from '@acorex/platform/layout/entity';
import { inject } from '@angular/core';
import { RootConfig } from './acorex-modules-financial-core.mjs';

//#region ---- Imports ----
//#endregion
//#region ---- Data Source Provider ----
class AXMFinancialCoreDataSourceDefinition {
    constructor() {
        this.entityService = inject(AXPEntityService);
        this.currencyQuery = {
            skip: 0,
            take: 1000,
            filter: {
                logic: 'and',
                filters: [
                    {
                        field: 'isDisabled',
                        operator: { type: 'equal' },
                        value: false,
                    },
                ],
            },
            sort: [{ field: 'title', dir: 'asc' }],
        };
        this.currencies = {
            name: 'currencies',
            title: 'Currencies',
            columns: [
                { name: 'code', title: 'Code', type: 'string', datatype: 'string' },
                { name: 'title', title: 'Title', type: 'string', datatype: 'string' },
            ],
            filters: [],
            textField: { name: 'title', title: 'Title' },
            valueField: { name: 'code', title: 'Code' },
            samples: [
                { code: 'USD', title: 'United States Dollar' },
                { code: 'EUR', title: 'Euro' },
                { code: 'GBP', title: 'British Pound' },
            ],
            source: () => {
                const dataAccessor = this.entityService
                    .withEntity(RootConfig.module.name, RootConfig.entities.currency.name)
                    .data();
                return new AXDataSource({
                    pageSize: 50,
                    key: 'code',
                    load: async (_e) => {
                        const result = await dataAccessor.query(this.currencyQuery);
                        const items = result.items.map((c) => ({
                            code: c.code,
                            title: c.title,
                        }));
                        return { items, total: items.length };
                    },
                    byKey: async (key) => {
                        const result = await dataAccessor.query(this.currencyQuery);
                        const item = result.items.find((c) => c.code === key);
                        return item ? { code: item.code, title: item.title } : undefined;
                    },
                });
            },
        };
    }
    async items() {
        return [this.currencies];
    }
}
//#endregion

export { AXMFinancialCoreDataSourceDefinition };
//# sourceMappingURL=acorex-modules-financial-core-data-source.provider-Do4rvgy4.mjs.map
