import { Controller, Put, Body, Req, UseGuards, HttpException, HttpStatus } from '@nestjs/common';
import { ApiBearerAuth, ApiTags, ApiOperation } from '@nestjs/swagger';
import { SeekerProfilesService } from './seeker_profiles.service';
import { Request } from 'express';
import { Public } from '../auth/public.decorator';
// Ensure you have JwtAuthGuard imported. Assuming it's in auth/jwt-auth.guard.ts, but let's use the typical approach.
// Actually, global guards might be applied if we just use @ApiBearerAuth, but let's safely use req.user.
import { JwtAuthGuard } from '../auth/jwt-auth.guard';

@ApiTags('seekerProfiles')
@ApiBearerAuth('access-token')
@UseGuards(JwtAuthGuard)
@Controller('seekerProfiles')
export class SeekerProfilesController {
  constructor(private readonly seekerProfilesService: SeekerProfilesService) {}

  @Put('me')
  @ApiOperation({ summary: 'Update logged-in seeker basic details' })
  async updateProfile(@Body() updateData: any, @Req() req: Request) {
    try {
      const user = (req as any).user;
      console.log('Update Profile Req User:', user);
      
      if (!user || !user.userId) {
        throw new HttpException('Unauthorized: Missing userId', HttpStatus.UNAUTHORIZED);
      }
      return await this.seekerProfilesService.updateBasicDetails(user.userId, updateData);
    } catch (error) {
      if (error instanceof HttpException) {
        throw error;
      }
      throw new HttpException(error.message || 'Error updating profile', HttpStatus.BAD_REQUEST);
    }
  }
}
