package cn.cslg.pas.controller;

import cn.cslg.pas.common.core.base.Constants;
import cn.cslg.pas.common.model.dto.SWQueryDTO;
import cn.cslg.pas.common.model.dto.ScratchWordsDTO;
import cn.cslg.pas.common.model.dto.ScratchWordsUpdateDTO;
import cn.cslg.pas.common.model.vo.ScratchWordsVO;
import cn.cslg.pas.common.utils.*;
import cn.cslg.pas.common.utils.auth.checkAuth;
import cn.cslg.pas.service.*;
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.*;

import java.util.*;

@Tag(name = "划词高亮")
@CrossOrigin
@RestController
@RequestMapping(Constants.API_VERSION_V2 + "/scratchWords")
@RequiredArgsConstructor(onConstructor_ = {@Lazy})
public class ScratchWordsController {
    private final ScratchWordsService scratchWordsService;

    @checkAuth(FunId = "/workspace/scratchWords/add")
    @Operation(summary = "新增划词高亮")
    @PostMapping("/add")
    public String add(@RequestBody ScratchWordsDTO scratchWordsDTO) {
        if (scratchWordsDTO == null) {
            return Response.error("请求参数为null");
        } else {
            scratchWordsService.add(scratchWordsDTO);
            return Response.success("新增划词高亮完成");
        }
    }
    @checkAuth(FunId = "/workspace/scratchWords/query")
    @Operation(summary = "查询划词高亮")
    @PostMapping("/query")
    public String query(@RequestBody SWQueryDTO swQueryDTO) {
        if (swQueryDTO != null) {
            return Response.success(scratchWordsService.queryAll(swQueryDTO));
        } else {
            return Response.error("查询失败");
        }
    }
    @checkAuth(FunId = "/workspace/scratchWords/query")
    @Operation(summary = "更新划词高亮")
    @PostMapping("/update")
    public String update(@RequestBody ScratchWordsUpdateDTO scratchWordsUpdateDTO){
        if (scratchWordsUpdateDTO != null) {
            scratchWordsService.update(scratchWordsUpdateDTO);
            return Response.success("更新成功");
        } else {
            return Response.error("更新失败");
        }
    }
    @checkAuth(FunId = "/workspace/scratchWords/delete")
    @Operation(summary = "删除划词高亮")
    @PostMapping("/delete")
    public String delete(@RequestBody List<Integer> ids){
        if (ids != null && ids.size() != 0) {
            scratchWordsService.delete(ids);
            return Response.success("删除成功");
        } else {
            return Response.error("删除失败");
        }
    }
}
