import { Controller, Get, Param, Query, Req, UseGuards } from '@nestjs/common';
import { ApiTags, ApiBearerAuth } from '@nestjs/swagger';
import { AuthGuard } from '@nestjs/passport';
import { SkillsService } from './skills.service';

@ApiTags('技能')
@Controller('skills')
export class SkillsController {
  constructor(private skillsService: SkillsService) {}

  @Get()
  findAll(@Query() query: { category?: string; difficulty?: string; search?: string; tag?: string }) {
    return this.skillsService.findAll(query);
  }

  @Get('marketplace')
  getMarketplace(@Req() req: any) {
    const userId = req.user?.userId;
    return this.skillsService.getMarketplace(userId);
  }

  @Get('categories')
  getCategories() {
    return this.skillsService.getCategories();
  }

  @Get('difficulties')
  getDifficulties() {
    return this.skillsService.getDifficulties();
  }

  @Get(':id')
  async findById(@Req() req: any, @Param('id') id: string) {
    const userId = req.user?.userId;
    const skill = await this.skillsService.findById(id, userId);
    if (!skill) return { error: '技能不存在' };
    return skill;
  }
}
