"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TypeOrmDeviceRepository = void 0;
const device_entity_1 = require("../entities/device.entity");
const data_source_1 = require("../data-source");
const device_mapper_1 = require("./mappers/device.mapper");
class TypeOrmDeviceRepository {
    get repository() {
        return data_source_1.AppDataSource.getRepository(device_entity_1.DeviceEntity);
    }
    async findById(id) {
        const entity = await this.repository.findOneBy({ id });
        return entity ? device_mapper_1.deviceMapper.toDomain(entity) : null;
    }
    async findByFingerprint(fingerprint) {
        const entity = await this.repository.findOneBy({ fingerprint });
        return entity ? device_mapper_1.deviceMapper.toDomain(entity) : null;
    }
    async findAll(options) {
        const entities = await this.repository.find({
            take: options?.limit,
            skip: options?.offset,
            order: { createdAt: 'DESC' },
        });
        return entities.map(device_mapper_1.deviceMapper.toDomain);
    }
    async save(device) {
        const entity = await this.repository.save(device_mapper_1.deviceMapper.toEntity(device));
        return device_mapper_1.deviceMapper.toDomain(entity);
    }
    async update(device) {
        const entity = await this.repository.save(device_mapper_1.deviceMapper.toEntity(device));
        return device_mapper_1.deviceMapper.toDomain(entity);
    }
    async delete(id) {
        await this.repository.delete(id);
    }
}
exports.TypeOrmDeviceRepository = TypeOrmDeviceRepository;
//# sourceMappingURL=typeorm-device.repository.js.map