package com.hotwj.platform.resourceManagement.company.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.hotwj.platform.resourceManagement.company.domain.bo.SysCompanyRoleBo;
import com.hotwj.platform.resourceManagement.company.domain.vo.SysCompanyRoleVo;
import com.hotwj.platform.resourceManagement.company.service.ISysCompanyRoleService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.web.core.BaseController;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/resourceManagement/companyRole")
@Tag(name = "企业角色", description = "企业角色权限配置")
public class SysCompanyRoleController extends BaseController {

    private final ISysCompanyRoleService sysCompanyRoleService;

    //    //@SaCheckPermission("resourceManagement:companyRole:list")
    @GetMapping("/list")
    @Operation(summary = "分页查询企业角色列表")
    public TableDataInfo<SysCompanyRoleVo> list(SysCompanyRoleBo bo, PageQuery pageQuery) {
        return sysCompanyRoleService.queryPageList(bo, pageQuery);
    }

    //@SaCheckPermission("resourceManagement:companyRole:query")
    @GetMapping("/{id}")
    @Operation(summary = "查询企业角色详情")
    public R<SysCompanyRoleVo> getInfo(@NotNull(message = "主键不能为空") @PathVariable Long id) {
        return R.ok(sysCompanyRoleService.queryById(id));
    }

    //@SaCheckPermission("resourceManagement:companyRole:add")
    @Log(title = "企业角色", businessType = BusinessType.INSERT)
    @PostMapping()
    @Operation(summary = "新增企业角色")
    public R<Void> add(@Validated(AddGroup.class) @RequestBody SysCompanyRoleBo bo) {
        return toAjax(sysCompanyRoleService.insertByBo(bo));
    }

    //@SaCheckPermission("resourceManagement:companyRole:edit")
    @Log(title = "企业角色", businessType = BusinessType.UPDATE)
    @PutMapping()
    @Operation(summary = "修改企业角色")
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody SysCompanyRoleBo bo) {
        return toAjax(sysCompanyRoleService.updateByBo(bo));
    }

    //@SaCheckPermission("resourceManagement:companyRole:remove")
    @Log(title = "企业角色", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @Operation(summary = "删除企业角色")
    public R<Void> remove(@NotEmpty(message = "主键不能为空") @PathVariable Long[] ids) {
        return toAjax(sysCompanyRoleService.deleteWithValidByIds(List.of(ids), true));
    }
}

