package com.example.dateplanner.services;

import com.example.dateplanner.models.entities.AppUser;
import com.example.dateplanner.repositories.AppUserRepository;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.userdetails.ReactiveUserDetailsService;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.crypto.password.PasswordEncoder;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.util.UUID;

@Slf4j
@RequiredArgsConstructor
public class UserService implements ReactiveUserDetailsService {
    private final AppUserRepository userRepository;
    private final PasswordEncoder passwordEncoder;

    @Override
    public Mono<UserDetails> findByUsername(String username) {
        log.info("username {}", username);
        return userRepository.findByPhone(username).flatMap(Mono::just).cast(UserDetails.class);
    }

    public Mono<AppUser> getByUuid(UUID uuid) {
        return userRepository.findById(uuid);
    }

    public Mono<AppUser> getUserByUuid(UUID uuid) {
        return userRepository.findById(uuid);
    }
}
