package com.yaoai.api.controller;

import com.yaoai.api.dto.project.ProjectCreateRequest;
import com.yaoai.api.dto.project.ProjectDTO;
import com.yaoai.api.dto.project.ProjectUpdateRequest;
import com.yaoai.api.service.ProjectService;
import com.yaoai.common.response.ApiResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "项目管理")
@RestController
@RequestMapping("/projects")
@RequiredArgsConstructor
public class ProjectController {

    private final ProjectService projectService;

    @Operation(summary = "创建项目")
    @PostMapping
    public ApiResponse<ProjectDTO> create(@Valid @RequestBody ProjectCreateRequest req) {
        return ApiResponse.success(projectService.create(req));
    }

    @Operation(summary = "获取我的项目列表")
    @GetMapping
    public ApiResponse<List<ProjectDTO>> list() {
        return ApiResponse.success(projectService.listByCurrentTenant());
    }

    @Operation(summary = "获取项目详情")
    @GetMapping("/{id}")
    public ApiResponse<ProjectDTO> get(@PathVariable Long id) {
        return ApiResponse.success(projectService.getById(id));
    }

    @Operation(summary = "更新项目")
    @PutMapping("/{id}")
    public ApiResponse<ProjectDTO> update(@PathVariable Long id,
                                          @Valid @RequestBody ProjectUpdateRequest req) {
        return ApiResponse.success(projectService.update(id, req));
    }

    @Operation(summary = "删除项目（软删除）")
    @DeleteMapping("/{id}")
    public ApiResponse<Void> delete(@PathVariable Long id) {
        projectService.delete(id);
        return ApiResponse.success();
    }
}
