const { asyncHandler } = require("../../middleware/errorHandler");
const ApiResponse = require("../../utils/apiResponse");
const adminProfileService = require("../../services/admin/profileService");

exports.getAdminProfile = asyncHandler(async (req, res) => {
    const data = await adminProfileService.getAdminProfile(req.admin?.id, req.query);
    ApiResponse.success(res, data);
});

/* exports.updateAdminProfile = asyncHandler(async (req, res) => {
  const data = await adminProfileService.updateAdminProfile(req.admin?.id, req.body);
  ApiResponse.success(res, data);
}); */

exports.changePassword = asyncHandler(async (req, res) => {
    const { currentPassword, newPassword, confirmPassword } = req.body;
    if (newPassword !== confirmPassword) {
        return ApiResponse.error(res, 'New password and confirm password do not match', 400);
    }
    const data = await adminProfileService.changePassword(req.admin?.id, currentPassword, newPassword);
    ApiResponse.success(res, data);
});

/* exports.setupTwoFactorAuth = asyncHandler(async (req, res) => {
  const data = await adminProfileService.setupTwoFactorAuth(req.admin?.id);
  ApiResponse.success(res, data);
}
); */

exports.verifyPassword2fa = asyncHandler(async (req, res) => {
    const ip = req.ip || req.connection.remoteAddress;
    const device = req.headers['user-agent'];
    const data = await adminProfileService.verifyPassword2fa(
        req.admin.id,
        req.body,
        ip,
        device
    );

    ApiResponse.success(res, data);
});

/* exports.disableTwoFactorAuth = asyncHandler(async (req, res) => {
  const data = await adminProfileService.disableTwoFactorAuth(req.admin?.id);
  ApiResponse.success(res, data);
}
); */

exports.enable2FA = asyncHandler(async (req, res) => {
    const data = await adminProfileService.enable2FA(req.admin?.id, req.body);
    ApiResponse.success(res, data);
});

exports.disable2FA = asyncHandler(async (req, res) => {
    const data = await adminProfileService.disable2FA(req.admin?.id, req.body);
    ApiResponse.success(res, data);
});

exports.resend2fa = asyncHandler(async (req, res) => {

  const ip = req.ip || req.connection.remoteAddress;
  const device = req.headers['user-agent'];
  await adminProfileService.resend2fa(req.admin?.id, ip, device);
  ApiResponse.success(res, null, 'Two factor email sent');
});

/* exports.getTwoFactorAuthStatus = asyncHandler(async (req, res) => {
  const data = await adminProfileService.getTwoFactorAuthStatus(req.admin?.id);
  ApiResponse.success(res, data);
}); */

/* exports.getAdminActivityLogs = asyncHandler(async (req, res) => {
  const data = await adminProfileService.getAdminActivityLogs(req.admin?.id, req.query);
  ApiResponse.success(res, data);
}); */

/* exports.getAdminLoginHistory = asyncHandler(async (req, res) => {
  const data = await adminProfileService.getAdminLoginHistory(req.admin?.id, req.query);
  ApiResponse.success(res, data);
}); */

/* exports.getAdminSessions = asyncHandler(async (req, res) => {
  const data = await adminProfileService.getAdminSessions(req.admin?.id);
  ApiResponse.success(res, data);
}); */

/* exports.terminateAdminSession = asyncHandler(async (req, res) => {
  const data = await adminProfileService.terminateAdminSession(req.admin?.id, req.params.sessionId);
  ApiResponse.success(res, data);
}); */

/* exports.terminateAllAdminSessions = asyncHandler(async (req, res) => {
  const data = await adminProfileService.terminateAllAdminSessions(req.admin?.id);
  ApiResponse.success(res, data);
}); */


