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.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
    ) {
        return new CreateUser(userRepository, roleRepository, passwordHasher, auditLogger, authPort);
    }

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

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

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

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

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

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

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

    @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);
    }
}
