package com.libreecm.controllers;

//import org.springframework.security.authentication.AnonymousAuthenticationToken;
//import org.springframework.security.core.Authentication;
//import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
//import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.libreecm.commonAPI.auxiliars.exceptions.*;
import com.libreecm.commonAPI.configuration.ComponentConfig;
//import com.LibreECM.DB.configuration.security.IAuthenticationFacade;
import com.libreecm.commonAPI.model.users.LibreECMUser;
import com.libreecm.consumers.UserConsumer;
 
@RestController
public class UserController extends BaseController {
 
    /**
     * A class that saves a User to the DDBB
     * @param user
     * @return
     * @throws AlreadyExistingUserException 
     * @throws AddUserOkException 
     */
    @RequestMapping(value="/user", method = RequestMethod.POST)
    public @ResponseBody LibreECMUser saveUser(@RequestBody LibreECMUser user) throws AlreadyExistingUserException, AddUserOkException {
    	//validateUser();
    	UserConsumer consumer = new UserConsumer();
    	return consumer.setUser(user, ComponentConfig.getConfig().getDbUserUrl());
    }
    
    /**
     * A class that gets a User from the DDBB
     * @param id String id
     * @return 
     */
    @RequestMapping(value="/user", method = RequestMethod.GET)
    public @ResponseBody LibreECMUser getUser(@RequestBody String id) {
    	//validateUser();
    	UserConsumer consumer = new UserConsumer();
    	return consumer.getUser(id, ComponentConfig.getConfig().getDbUserUrl());
    }

    /**
     * A class that gets the current User from the client
     * @return 
     */
    @RequestMapping(value="/currentuser", method = RequestMethod.GET)
    public @ResponseBody LibreECMUser getCurrentUser() {
    	//validateUser();
    	UserConsumer consumer = new UserConsumer();
    	return consumer.getCurrentUser(ComponentConfig.getConfig().getInputCurrentUserUrl());
    }
}