const UnitOfWork = require('../../database/UnitOfWork');
const CompanyProfileService = require('../../services/profile/company/CompanyProfileService');
const { logger } = require('../../middleware/logger');

class CompanyProfileController {
  static async completeProfile(req, res) {
    const userId = req.user.userId;
    const profileData = req.body;
    const unitOfWork = new UnitOfWork();
    await unitOfWork.start();
    logger.info('CompanyProfileController:completeProfile:start', { userId, profileData });
    try {
      await CompanyProfileService.completeProfile(userId, profileData, unitOfWork);
      await unitOfWork.commit();
      logger.info('CompanyProfileController:completeProfile:success', { userId });
      res.json({ success: true });
    } catch (error) {
      await unitOfWork.rollback(error);
      logger.error('CompanyProfileController:completeProfile:error', { userId, error });
      res.status(400).json({ success: false, message: error.message });
    }
  }
}

module.exports = CompanyProfileController;
