"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var __param = (this && this.__param) || function (paramIndex, decorator) {
    return function (target, key) { decorator(target, key, paramIndex); }
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.DashboardItemService = void 0;
const api_locale_1 = require("@hed-hog/api-locale");
const api_pagination_1 = require("@hed-hog/api-pagination");
const api_prisma_1 = require("@hed-hog/api-prisma");
const common_1 = require("@nestjs/common");
let DashboardItemService = class DashboardItemService {
    constructor(prismaService, paginationService, localeService) {
        this.prismaService = prismaService;
        this.paginationService = paginationService;
        this.localeService = localeService;
    }
    async getAllDashboardItems(paginationParams, locale, dashboardId) {
        return this.paginationService.paginate(this.prismaService.dashboard_item, paginationParams, {
            where: dashboardId ? { dashboard_id: dashboardId } : undefined,
            include: {
                dashboard: {
                    include: {
                        dashboard_locale: {
                            include: {
                                locale: true,
                            },
                        },
                    },
                },
                dashboard_component: {
                    include: {
                        dashboard_component_locale: {
                            include: {
                                locale: true,
                            },
                        },
                    },
                },
            },
            orderBy: {
                id: 'desc',
            },
        }, 'dashboardItem');
    }
    async createDashboardItem(data, locale) {
        return this.prismaService.dashboard_item.create({
            data: {
                dashboard_id: data.dashboard_id,
                component_id: data.component_id,
                width: data.width,
                height: data.height,
                x_axis: data.x_axis,
                y_axis: data.y_axis,
            },
            include: {
                dashboard: true,
                dashboard_component: true,
            },
        });
    }
    async deleteDashboardItem(id, locale) {
        const item = await this.prismaService.dashboard_item.findUnique({
            where: { id },
        });
        if (!item) {
            throw new common_1.NotFoundException((0, api_locale_1.getLocaleText)('dashboardItemNotFound', locale, 'Dashboard item not found'));
        }
        await this.prismaService.dashboard_item.delete({
            where: { id },
        });
        return { success: true };
    }
};
exports.DashboardItemService = DashboardItemService;
exports.DashboardItemService = DashboardItemService = __decorate([
    (0, common_1.Injectable)(),
    __param(0, (0, common_1.Inject)((0, common_1.forwardRef)(() => api_prisma_1.PrismaService))),
    __param(1, (0, common_1.Inject)((0, common_1.forwardRef)(() => api_pagination_1.PaginationService))),
    __param(2, (0, common_1.Inject)((0, common_1.forwardRef)(() => api_locale_1.LocaleService))),
    __metadata("design:paramtypes", [api_prisma_1.PrismaService,
        api_pagination_1.PaginationService,
        api_locale_1.LocaleService])
], DashboardItemService);
//# sourceMappingURL=dashboard-item.service.js.map