import { Request, Response, NextFunction } from 'express';
import { UserService } from '../services/UserService';
import { UserView } from '../views/UserView';

export class ProfileController {
  constructor(private userService = new UserService()) {}

  enhance = async (req: Request, res: Response, next: NextFunction) => {
    try {
      const enhanced = await this.userService.enhanceProfileFields(req.userId!, req.body);
      res.json({ enhanced });
    } catch (err) {
      next(err);
    }
  };

  fetchLinkedIn = async (req: Request, res: Response, next: NextFunction) => {
    try {
      const result = await this.userService.fetchLinkedInProfile(req.body.linkedinUrl);
      res.json(result);
    } catch (err) {
      next(err);
    }
  };

  importLinkedIn = async (req: Request, res: Response, next: NextFunction) => {
    try {
      const user = await this.userService.importFromLinkedIn(req.userId!, req.body);
      res.json(UserView.toPublic(user));
    } catch (err) {
      next(err);
    }
  };
}
