package com.xindazhou.business.controller.admin.community.sensitive;

import com.xindazhou.business.controller.admin.community.sensitive.vo.SensitiveWordPageReqVO;
import com.xindazhou.business.controller.admin.community.sensitive.vo.SensitiveWordRespVO;
import com.xindazhou.business.controller.admin.community.sensitive.vo.SensitiveWordSaveReqVO;
import com.xindazhou.business.service.community.sensitive.SensitiveWordService;
import com.xindazhou.framework.common.pojo.CommonResult;
import com.xindazhou.framework.common.pojo.PageResult;
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.validation.Valid;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import static com.xindazhou.framework.common.pojo.CommonResult.success;

/**
 * 管理后台 - 敏感词管理 Controller
 *
 * @author xindazhou
 */
@Tag(name = "管理后台 - 敏感词管理")
@RestController("communitySensitiveWordController")
@RequestMapping("/admin-api/community/sensitive-word")
@Validated
@Slf4j
public class SensitiveWordController {

    @Resource
    private SensitiveWordService sensitiveWordService;

    @PostMapping("/create")
    @Operation(summary = "创建敏感词")
    @PreAuthorize("@ss.hasPermission('community:sensitive-word:create')")
    public CommonResult<Long> createSensitiveWord(@Valid @RequestBody SensitiveWordSaveReqVO createReqVO) {
        Long id = sensitiveWordService.createSensitiveWord(createReqVO);
        return success(id);
    }

    @PutMapping("/update")
    @Operation(summary = "更新敏感词")
    @PreAuthorize("@ss.hasPermission('community:sensitive-word:update')")
    public CommonResult<Boolean> updateSensitiveWord(@Valid @RequestBody SensitiveWordSaveReqVO updateReqVO) {
        sensitiveWordService.updateSensitiveWord(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除敏感词")
    @Parameter(name = "id", description = "敏感词ID", required = true, example = "1")
    @PreAuthorize("@ss.hasPermission('community:sensitive-word:delete')")
    public CommonResult<Boolean> deleteSensitiveWord(@RequestParam("id") Long id) {
        sensitiveWordService.deleteSensitiveWord(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得敏感词")
    @Parameter(name = "id", description = "敏感词ID", required = true, example = "1")
    @PreAuthorize("@ss.hasPermission('community:sensitive-word:query')")
    public CommonResult<SensitiveWordRespVO> getSensitiveWord(@RequestParam("id") Long id) {
        SensitiveWordRespVO sensitiveWord = sensitiveWordService.getSensitiveWord(id);
        return success(sensitiveWord);
    }

    @GetMapping("/page")
    @Operation(summary = "获得敏感词分页列表")
    @PreAuthorize("@ss.hasPermission('community:sensitive-word:query')")
    public CommonResult<PageResult<SensitiveWordRespVO>> getSensitiveWordPage(@Valid SensitiveWordPageReqVO pageReqVO) {
        PageResult<SensitiveWordRespVO> pageResult = sensitiveWordService.getSensitiveWordPage(pageReqVO);
        return success(pageResult);
    }

}

