package top.imwork.window.silos.controller.upms;

import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;

import top.imwork.commons.core.base.BaseController;
import top.imwork.commons.core.pojo.DeleteParams;
import top.imwork.commons.core.pojo.ResponseMsg;
import top.imwork.window.silos.convert.SysRoleConvert;
import top.imwork.window.silos.pojo.bo.SysRoleBO;
import top.imwork.window.silos.pojo.bo.SysRoleResultBO;
import top.imwork.window.silos.pojo.po.SysRoleListParamVO;
import top.imwork.window.silos.pojo.po.SysRoleParamVO;
import top.imwork.window.silos.service.upms.ISysRoleService;

import java.util.List;

/**
 * 角色信息
 *
 * @author jiangxiaowei
 * email: e-jiangxiaowei@outlook.com
 * date: 2025-12-09 16:29:22
 */
@RestController
@RequestMapping("/upms/sysrole")
public class SysRoleServiceController extends BaseController {

    @Resource
    public ISysRoleService sysRoleService;

    /**
     * 根据id查询数据
     * @param id long类型的id
     * @return 返回查询结果
     */
    @GetMapping("/info/{id}")
    public ResponseMsg info(@PathVariable("id") Long id){
        return ResponseMsg.buildResponse(sysRoleService.info(id));
    }

    /**
     * 新增/修改info
     * @param sysRoleParamVO 实体信息
     * @return responseMsg 操作结果
     */
    @PostMapping("/save")
    public ResponseMsg save(@RequestBody @Valid SysRoleParamVO sysRoleParamVO){
        SysRoleBO sysRoleBO = sysRoleService.save(SysRoleConvert.sysRoleParamVoToDto(sysRoleParamVO));
        return ResponseMsg.buildResponse(SysRoleConvert.sysRoleBoToVo(sysRoleBO));
    }

    /**
     * 根据id删除角色信息
     * @param id id
     * @return true/false 成功/失败
     */
    @GetMapping("/delete/{id}")
    public ResponseMsg delete(@PathVariable("id") Long id){
        String[] idArr = new String[1];
        idArr[0] = String.valueOf(id);
        return sysRoleService.deleteByIds(idArr)? ResponseMsg.ok() : ResponseMsg.fail();
    }

    /**
     * 批量逻辑删除信息
     *
     * @param dto 删除条件
     * @return true/false 是否删除成功
     */
    @PostMapping("/deleteByIds")
    public ResponseMsg deleteByIds(@RequestBody DeleteParams dto){
        return sysRoleService.deleteByIds(dto.getIdsArr())? ResponseMsg.ok() : ResponseMsg.fail();
    }

    @PostMapping("/queryPage")
    public ResponseMsg queryPage(@RequestBody @Valid SysRoleListParamVO sysRoleListParamVO) {
        SysRoleResultBO sysRoleResultBO = sysRoleService.queryPage(SysRoleConvert.sysRoleListParamVoToDTO(sysRoleListParamVO));
        return ResponseMsg.buildResponse(SysRoleConvert.sysRoleResultBoToVo(sysRoleResultBO));
    }

    @GetMapping("/selectAll")
    public ResponseMsg selectAll(){
        List<SysRoleBO> list = sysRoleService.selectAll();
        return ResponseMsg.buildResponse(SysRoleConvert.sysRoleBoListToSysRoleVoList(list));
    }
}
