import { Network } from '../../../domain/entities/network';
import { INetworkRepository } from '../../../domain/repositories/network-repository';
import { ICacheService } from '../../ports/cache-service';

const CACHE_KEY = 'networks:list';
const CACHE_TTL_SECONDS = 5 * 60; // 5 minutes

export class GetNetworksListUseCase {
  constructor(
    private readonly networkRepository: INetworkRepository,
    private readonly cacheService: ICacheService,
  ) {}

  async execute(): Promise<Network[]> {
    return this.cacheService.wrap<Network[]>(
      CACHE_KEY,
      () => this.networkRepository.findActive(),
      CACHE_TTL_SECONDS,
    );
  }
}
