package com.imprimelibros.erp.users;

import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements UserService {

    private UserDao userDao;

    public UserServiceImpl(UserDao userDao) {
        this.userDao = userDao;
    }

     @Override
    public UserDetails loadUserByUsername(String username) {
        User user = userDao.findByUserNameIgnoreCaseAndEnabledTrueAndDeletedFalse(username)
                .orElseThrow(() -> new UsernameNotFoundException("No existe usuario activo: " + username));
        return new UserDetailsImpl(user);
    }
}
