const { loginService, getUserService, logoutService } = require('../../services/auth/AuthService.js');
const { successResponse, errorResponse, messageSuccessResponse } = require('../../utils/Response.js');
const { validateLoginRequest } = require('../../validators/auth/LoginValidators.js');

exports.login = async (req, res) => {
    try {
        const validated = validateLoginRequest(req.body);
        const { user, token } = await loginService(validated, req);
        return successResponse(res, { ...user, token }, 'Login success');
    } catch (error) {
        return errorResponse(res, error);
    }
};

exports.getUser = async (req, res) => {
    try {
        const data = await getUserService(req);
        return successResponse(res, data, 'Success get user');
    } catch (error) {
        return errorResponse(res, error);
    }
};

exports.logout = async (req, res) => {
    try {
        await logoutService(req);
        return messageSuccessResponse(res, 'Logout success', 200);
    } catch (error) {
        return errorResponse(res, error);
    }
}