package com.tashow.cloud.ai.controller.admin.aisample;

import com.tashow.cloud.ai.controller.admin.aisample.vo.AiSampleTagListRespVO;
import com.tashow.cloud.ai.controller.admin.aisample.vo.AiSampleTagPageReqVO;
import com.tashow.cloud.ai.controller.admin.aisample.vo.AiSampleTagGroupRespVO;
import com.tashow.cloud.ai.controller.admin.aisample.vo.AiSampleTagSaveReqVO;
import com.tashow.cloud.ai.dal.dataobject.aisample.AiSampleTagDO;
import com.tashow.cloud.ai.service.aisample.AiSampleTagService;
import com.tashow.cloud.common.pojo.CommonResult;
import com.tashow.cloud.common.pojo.PageResult;
import com.tashow.cloud.common.util.object.BeanUtils;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.annotation.security.PermitAll;
import jakarta.validation.Valid;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.tashow.cloud.common.pojo.CommonResult.success;


@Tag(name = "管理后台 - 样本标签库")
@RestController
@RequestMapping("/ai/sampleTag")
@Validated
public class AiSampleTagController {

    @Resource
    private AiSampleTagService aiSampleTagService;

    @PostMapping("/create")
    @Operation(summary = "创建样本标签库")
//    @PreAuthorize("@ss.hasPermission('ai:sampleTag:create')")
    @PermitAll
    public CommonResult<Long> createAiSampleTag(@Valid @RequestBody AiSampleTagSaveReqVO createReqVO) {
        return success(aiSampleTagService.createAiSampleTag(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新样本标签库")
//    @PreAuthorize("@ss.hasPermission('ai:sampleTag:update')")
    @PermitAll
    public CommonResult<Boolean> updateAiSampleTag(@Valid @RequestBody AiSampleTagSaveReqVO updateReqVO) {
        aiSampleTagService.updateAiSampleTag(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除样本标签库")
    @Parameter(name = "id", description = "编号", required = true)
//    @PreAuthorize("@ss.hasPermission('ai:sampleTag:delete')")
    @PermitAll
    public CommonResult<Boolean> deleteAiSampleTag(@RequestParam("id") Long id) {
        aiSampleTagService.deleteAiSampleTag(id);
        return success(true);
    }

    @GetMapping("/list")
    @Operation(summary = "获得样本标签库列表")
//    @PreAuthorize("@ss.hasPermission('ai:sampleTag:query')")
    @PermitAll
    public CommonResult<List<AiSampleTagListRespVO>> getAiSampleTagList() {
        return success(BeanUtils.toBean(aiSampleTagService.getAiSampleTagList(), AiSampleTagListRespVO.class));
    }

    @GetMapping("/group-list-by-tag-id")
    @Operation(summary = "根据标签 id 获取分组")
    @Parameter(name = "tagId", description = "标签 id", required = true)
    @PermitAll
    public CommonResult<List<AiSampleTagGroupRespVO>> getGroupListByTagId(@RequestParam("tagId") Long tagId) {
        return success(BeanUtils.toBean(aiSampleTagService.getGroupListByTagId(tagId), AiSampleTagGroupRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得样本标签库分页")
//    @PreAuthorize("@ss.hasPermission('ai:sampleTag:query')")
    @PermitAll
    public CommonResult<PageResult<AiSampleTagDO>> getAiSampleTagPage(@Valid AiSampleTagPageReqVO pageReqVO) {
        PageResult<AiSampleTagDO> pageResult = aiSampleTagService.getAiSampleTagPage(pageReqVO);
        return success(pageResult);
    }

}
