"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "FloorStore", {
    enumerable: true,
    get: function() {
        return FloorStore;
    }
});
const _keydiffcache = require("../utils/cache/key-diff.cache");
class FloorStore extends _keydiffcache.KeyDiffCache {
    floorService;
    logger;
    constructor(floorService, loggerFactory){
        super(), this.floorService = floorService;
        this.logger = loggerFactory(FloorStore.name);
    }
    async loadStore() {
        const floors = await this.floorService.list();
        const keyValues = floors.map((floor)=>({
                key: floor.id,
                value: this.floorService.toDto(floor)
            }));
        await this.setKeyValuesBatch(keyValues, true);
    }
    async listCache() {
        const floors = await this.getAllValues();
        if (floors?.length) {
            return floors;
        }
        await this.loadStore();
        return await this.getAllValues();
    }
    async create(input) {
        const floor = await this.floorService.create(input);
        const floorDto = this.floorService.toDto(floor);
        await this.setKeyValue(floor.id, floorDto, true);
        return floorDto;
    }
    async delete(floorId) {
        await this.floorService.delete(floorId);
        await this.deleteKeyValue(floorId);
    }
    async getFloor(floorId) {
        let floor = await this.getValue(floorId);
        if (floor) {
            return floor;
        }
        const dbFloor = await this.floorService.get(floorId);
        const floorDto = this.floorService.toDto(dbFloor);
        await this.setKeyValue(floorId, floorDto, true);
        return floorDto;
    }
    async update(floorId, input) {
        const floor = await this.floorService.update(floorId, input);
        const floorDto = this.floorService.toDto(floor);
        await this.setKeyValue(floorId, floorDto, true);
        return floorDto;
    }
    async updateName(floorId, name) {
        const floor = await this.floorService.updateName(floorId, name);
        const floorDto = this.floorService.toDto(floor);
        await this.setKeyValue(floorId, floorDto, true);
        return floorDto;
    }
    async updateFloorOrder(floorId, order) {
        const floor = await this.floorService.updateOrder(floorId, order);
        const floorDto = this.floorService.toDto(floor);
        await this.setKeyValue(floorId, floorDto, true);
        return floorDto;
    }
    async addOrUpdatePrinter(floorId, position) {
        const floor = await this.floorService.addOrUpdatePrinter(floorId, position);
        const floorDto = this.floorService.toDto(floor);
        await this.setKeyValue(floorId, floorDto, true);
        return floorDto;
    }
    async removePrinter(floorId, printerId) {
        const floor = await this.floorService.removePrinter(floorId, printerId);
        const floorDto = this.floorService.toDto(floor);
        await this.setKeyValue(floorId, floorDto, true);
        return floorDto;
    }
    async removePrinterFromAnyFloor(printerId) {
        await this.floorService.deletePrinterFromAnyFloor(printerId);
        await this.loadStore();
    }
}

//# sourceMappingURL=floor.store.js.map