package cn.cslg.pas.controller;

import cn.cslg.pas.common.core.base.Constants;
import cn.cslg.pas.common.utils.Response;
import cn.cslg.pas.service.ProjectFieldService;
import cn.cslg.pas.service.ProjectFieldTreeService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Tag(name = "字段")
@RestController
@RequestMapping(Constants.API_VERSION_V2 + "/field")
@RequiredArgsConstructor(onConstructor_ = {@Lazy})
public class FieldController {

    private final ProjectFieldService projectFieldService;
    private final ProjectFieldTreeService projectFieldTreeService;

    @GetMapping("system")
    @Operation(summary = "根据专题库ID获取所有字段")
    public String getSystemField(Integer projectId) {
        return Response.success(projectFieldService.getSystemField(projectId));
    }

    @GetMapping("custom")
    @Operation(summary = "获取专题库自定义字段列表")
    public String getCustom(Integer projectId) {
        return Response.success(projectFieldService.getCustomField(projectId));
    }

    @GetMapping("/tree/{fieldId}")
    @Operation(summary = "根据ID获取树形自定义字段")
    public String getTreeList(@PathVariable Integer fieldId) {
        return Response.success(projectFieldTreeService.getProjectFieldTreeNodeByFieldId(fieldId));
    }
}
