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

import com.tashow.cloud.ai.controller.admin.aisample.vo.AiSampleTagGroupRespVO;
import com.tashow.cloud.ai.controller.admin.aisample.vo.AiSampleTagGroupSaveReqVO;
import com.tashow.cloud.ai.dal.dataobject.aisample.AiSampleTagGroupDO;
import com.tashow.cloud.ai.service.aisample.AiSampleTagGroupService;
import com.tashow.cloud.common.pojo.CommonResult;
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/sampleTagGroup")
@Validated
public class AiSampleTagGroupController {

    @Resource
    private AiSampleTagGroupService aiSampleTagGroupService;

    @PostMapping("/create")
    @Operation(summary = "创建样本标签分组库")
//    @PreAuthorize("@ss.hasPermission('ai:sampleTagGroup:create')")
    @PermitAll
    public CommonResult<Long> createAiSampleTagGroup(@Valid @RequestBody AiSampleTagGroupSaveReqVO createReqVO) {
        return success(aiSampleTagGroupService.createAiSampleTagGroup(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新样本标签分组库")
//    @PreAuthorize("@ss.hasPermission('ai:sampleTagGroup:update')")
    @PermitAll
    public CommonResult<Boolean> updateAiSampleTagGroup(@Valid @RequestBody AiSampleTagGroupSaveReqVO updateReqVO) {
        aiSampleTagGroupService.updateAiSampleTagGroup(updateReqVO);
        return success(true);
    }

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

    @GetMapping("/list")
    @Operation(summary = "获得样本标签分组库列表")
//    @PreAuthorize("@ss.hasPermission('ai:sampleTagGroup:query')")
    @PermitAll
    public CommonResult<List<AiSampleTagGroupRespVO>> getAiSampleTagGroupPage() {
        List<AiSampleTagGroupDO> aiSampleTagGroupList = aiSampleTagGroupService.getAiSampleTagGroupList();
        return success(BeanUtils.toBean(aiSampleTagGroupList, AiSampleTagGroupRespVO.class));
    }

}