package de.effigenix.infrastructure.config;

import de.effigenix.application.usermanagement.*;
import de.effigenix.domain.usermanagement.RoleRepository;
import de.effigenix.domain.usermanagement.UserRepository;
import de.effigenix.shared.persistence.UnitOfWork;
import de.effigenix.shared.security.AuthorizationPort;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Spring configuration for use case beans.
 *
 * Use cases are no longer @Service-annotated; they are instantiated
 * explicitly here with their dependencies injected via constructor.
 */
@Configuration
public class UseCaseConfiguration {

    @Bean
    public CreateUser createUser(
            UserRepository userRepository,
            RoleRepository roleRepository,
            PasswordHasher passwordHasher,
            AuditLogger auditLogger,
            AuthorizationPort authPort,
            UnitOfWork unitOfWork
    ) {
        return new CreateUser(userRepository, roleRepository, passwordHasher, auditLogger, authPort, unitOfWork);
    }

    @Bean
    public AuthenticateUser authenticateUser(
            UserRepository userRepository,
            PasswordHasher passwordHasher,
            SessionManager sessionManager,
            AuditLogger auditLogger,
            UnitOfWork unitOfWork
    ) {
        return new AuthenticateUser(userRepository, passwordHasher, sessionManager, auditLogger, unitOfWork);
    }

    @Bean
    public ChangePassword changePassword(
            UserRepository userRepository,
            PasswordHasher passwordHasher,
            AuditLogger auditLogger,
            AuthorizationPort authPort,
            UnitOfWork unitOfWork
    ) {
        return new ChangePassword(userRepository, passwordHasher, auditLogger, authPort, unitOfWork);
    }

    @Bean
    public UpdateUser updateUser(
            UserRepository userRepository,
            AuditLogger auditLogger,
            AuthorizationPort authPort,
            UnitOfWork unitOfWork
    ) {
        return new UpdateUser(userRepository, auditLogger, authPort, unitOfWork);
    }

    @Bean
    public AssignRole assignRole(
            UserRepository userRepository,
            RoleRepository roleRepository,
            AuditLogger auditLogger,
            AuthorizationPort authPort,
            UnitOfWork unitOfWork
    ) {
        return new AssignRole(userRepository, roleRepository, auditLogger, authPort, unitOfWork);
    }

    @Bean
    public RemoveRole removeRole(
            UserRepository userRepository,
            RoleRepository roleRepository,
            AuditLogger auditLogger,
            AuthorizationPort authPort,
            UnitOfWork unitOfWork
    ) {
        return new RemoveRole(userRepository, roleRepository, auditLogger, authPort, unitOfWork);
    }

    @Bean
    public LockUser lockUser(
            UserRepository userRepository,
            AuditLogger auditLogger,
            AuthorizationPort authPort,
            UnitOfWork unitOfWork
    ) {
        return new LockUser(userRepository, auditLogger, authPort, unitOfWork);
    }

    @Bean
    public UnlockUser unlockUser(
            UserRepository userRepository,
            AuditLogger auditLogger,
            AuthorizationPort authPort,
            UnitOfWork unitOfWork
    ) {
        return new UnlockUser(userRepository, auditLogger, authPort, unitOfWork);
    }

    @Bean
    public GetUser getUser(UserRepository userRepository, AuthorizationPort authPort) {
        return new GetUser(userRepository, authPort);
    }

    @Bean
    public ListUsers listUsers(UserRepository userRepository, AuthorizationPort authPort) {
        return new ListUsers(userRepository, authPort);
    }
}
