package com.sckw.system.controller;

import com.sckw.core.web.response.BaseResult;
import com.sckw.core.web.response.result.PageDataResult;
import com.sckw.system.model.vo.req.SysDictTypeReqVo;
import com.sckw.system.model.vo.res.SysDictTypeResp;
import com.sckw.system.service.SysDictTypeService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 字典类型控制器 (MyBatis-Flex)
 * @author system
 * @date 2024
 */
@Tag(name = "字典类型管理")
@RestController
@RequestMapping("/flex/sysDictType")
@RequiredArgsConstructor
public class SysDictTypeFlexController {

    private final SysDictTypeService sysDictTypeService;

    /**
     * 新增字典类型
     */
    @Operation(summary = "新增字典类型")
    @PostMapping("/insert")
    public BaseResult<Integer> insert(@RequestBody SysDictTypeReqVo reqVo) {
        return BaseResult.success(sysDictTypeService.insert(reqVo.getEntity()));
    }


    /**
     * 逻辑删除字典类型
     */
    @Operation(summary = "逻辑删除字典类型")
    @PostMapping("/logicDelete")
    public BaseResult<Integer> logicDeleteById(@RequestBody SysDictTypeReqVo reqVo) {
        int rows = sysDictTypeService.logicDeleteById(reqVo.getId());
        return BaseResult.success(rows);
    }

    /**
     * 更新字典类型
     */
    @Operation(summary = "更新字典类型")
    @PostMapping("/update")
    public BaseResult<Integer> update(@RequestBody SysDictTypeReqVo reqVo) {
        int rows = sysDictTypeService.update(reqVo.getEntity());
        return BaseResult.success(rows);
    }


    /**
     * 分页查询字典类型
     */
    @Operation(summary = "分页查询字典类型")
    @PostMapping("/selectPage")
    public BaseResult<PageDataResult<SysDictTypeResp>> selectPage(@RequestBody SysDictTypeReqVo reqVo) {

        return BaseResult.success(sysDictTypeService.selectPage(reqVo));
    }

    /**
     * 搜索字典类型（支持下拉选择，支持输入搜索）
     */
    @Operation(summary = "搜索字典类型下拉列表", description = "支持按名称或类型模糊搜索，返回id、name、type字段")
    @PostMapping("/searchForSelect")
    public BaseResult<List<SysDictTypeResp>> searchForSelect(@RequestBody SysDictTypeReqVo reqVo) {
        return BaseResult.success(sysDictTypeService.searchForSelect(reqVo.getKeyword()));
    }

}
