package com.ningdatech.pmapi.portrait.controller;

import com.ningdatech.basic.model.PageVo;
import com.ningdatech.log.annotation.WebLog;
import com.ningdatech.pmapi.portrait.manage.TagManage;
import com.ningdatech.pmapi.portrait.model.dto.TagDTO;
import com.ningdatech.pmapi.portrait.model.dto.TagToProjectDTO;
import com.ningdatech.pmapi.portrait.model.req.TagPageReq;
import com.ningdatech.pmapi.portrait.model.vo.TagVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @Classname TagController
 * @Description
 * @Date 2023/8/2 14:11
 * @Author PoffyZhang
 */
@RestController
@RequiredArgsConstructor
@Api(tags = "项目画像-标签")
@RequestMapping("/api/v1/portrait/tag")
public class TagController {
    private final TagManage tagManage;

    @GetMapping("/list/{areaCode}")
    @ApiOperation("按区域查询标签列表")
    public PageVo<TagVO> list(@PathVariable String areaCode, TagPageReq req) {
        return tagManage.list(areaCode,req);
    }

    @PostMapping("/save")
    @ApiOperation("保存标签")
    @WebLog("保存标签")
    public String save(@Valid @RequestBody TagDTO dto) {
        return tagManage.save(dto);
    }

    @PostMapping("/delete/{id}")
    @ApiOperation("删除标签")
    @WebLog("删除标签")
    public String save(@PathVariable Long id) {
        return tagManage.delete(id);
    }

    @PostMapping("/save-to-project")
    @ApiOperation("设置标签到项目")
    @WebLog("设置标签到项目")
    public String saveToProject(@Valid @RequestBody List<TagToProjectDTO> dtos) {
        return tagManage.saveToProject(dtos);
    }

    @PostMapping("/remove-tag-to-project")
    @ApiOperation("项目删除标签")
    @WebLog("项目删除标签")
    public String removeTagToProject(@Valid @RequestBody TagToProjectDTO dto) {
        return tagManage.removeTagToProject(dto);
    }
}
