package application.usecase;

import application.port.input.IAppConfig;
import domain.entity.AppConfiguration;
import domain.repository.AppConfigRepository;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import jakarta.ws.rs.NotFoundException;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@ApplicationScoped
public class GetAppConfigUseCase implements IAppConfig {

    private final AppConfigRepository appConfigRepository;

    @Inject
    public GetAppConfigUseCase(AppConfigRepository appConfigRepository) {
        this.appConfigRepository = appConfigRepository;
    }

    public AppConfiguration execute(String appName) {

        return appConfigRepository.findConfigByAppName(appName)
                .orElseThrow(() -> new NotFoundException("Configuracion no encontrada para la app: " + appName));
    }

}