"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TypeOrmNetworkRepository = void 0;
const network_entity_1 = require("../entities/network.entity");
const data_source_1 = require("../data-source");
const network_mapper_1 = require("./mappers/network.mapper");
class TypeOrmNetworkRepository {
    get repository() {
        return data_source_1.AppDataSource.getRepository(network_entity_1.NetworkEntity);
    }
    async findById(id) {
        const entity = await this.repository.findOneBy({ id });
        return entity ? network_mapper_1.networkMapper.toDomain(entity) : null;
    }
    async findByName(name) {
        const entity = await this.repository.findOneBy({ name });
        return entity ? network_mapper_1.networkMapper.toDomain(entity) : null;
    }
    async findByChainId(chainId) {
        const entity = await this.repository.findOneBy({ chainId });
        return entity ? network_mapper_1.networkMapper.toDomain(entity) : null;
    }
    async findActive() {
        const entities = await this.repository.find({
            where: { status: 'active' },
            order: { createdAt: 'DESC' },
        });
        return entities.map(network_mapper_1.networkMapper.toDomain);
    }
    async findAll(options) {
        const entities = await this.repository.find({
            take: options?.limit,
            skip: options?.offset,
            order: { createdAt: 'DESC' },
        });
        return entities.map(network_mapper_1.networkMapper.toDomain);
    }
    async save(network) {
        const entity = await this.repository.save(network_mapper_1.networkMapper.toEntity(network));
        return network_mapper_1.networkMapper.toDomain(entity);
    }
    async update(network) {
        const entity = await this.repository.save(network_mapper_1.networkMapper.toEntity(network));
        return network_mapper_1.networkMapper.toDomain(entity);
    }
    async delete(id) {
        await this.repository.delete(id);
    }
}
exports.TypeOrmNetworkRepository = TypeOrmNetworkRepository;
//# sourceMappingURL=typeorm-network.repository.js.map