package com.example.cezenPBX.service;

import com.example.cezenPBX.DAO.UserOpsDAO;
import com.example.cezenPBX.DTO.ReturnStatus;
import com.example.cezenPBX.entity.user.UserEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PbxUserService {

    @Autowired
    private UserOpsDAO userOpsDAO;

    @Autowired
    private PasswordEncoder passwordEncoder;


    // must perform the sanity checks before being set to the database
    // method will return a faulty return status if the damin exists
    public ReturnStatus adminSetUserNamePasswordSet(String userName, String password, String confirmPassword, String email){
        // password will be checked here
        if(!password.equals(confirmPassword)){
            return new ReturnStatus(false, "Passwords do not match", "Passwords do not match");
        }
        // password encryption
        UserEntity userEntity = new UserEntity(userName, passwordEncoder.encode(password), email);

        // commit the username and password to the database
        return userOpsDAO.adminSetUsernameAndPassword(userEntity);
    }
}
