import { Controller, Post, Get, Body } from "@nestjs/common"
import { Public } from "../../common/decorators/public.decorator"
import { CareerAdviceService, CareerProfile, ChatMessage } from "./career-advice.service"
import { CurrentUser } from "../../common/decorators/current-user.decorator"

@Controller("career-advice")
export class CareerAdviceController {
  constructor(private service: CareerAdviceService) {}

  @Post("analyze")
  async analyze(
    @Body() profile: CareerProfile,
    @CurrentUser("userId") userId: string,
  ) {
    if (!profile.major || !profile.major.trim()) {
      return { error: "请填写你的专业" }
    }
    return this.service.analyze(profile)
  }

  @Post("chat")
  async chat(
    @Body() body: { message: string; history: ChatMessage[] },
    @CurrentUser("userId") userId: string,
  ) {
    if (!body.message || !body.message.trim()) {
      return { error: "请输入消息" }
    }
    return this.service.chat(body.message, body.history || [])
  }

  @Get("positions")
  @Public()
  async positions() {
    return this.service.getHotPositions()
  }
}
