package com.zhongshu.card.server.core.controller.scene;

import com.github.microservice.auth.security.annotations.ResourceAuth;
import com.github.microservice.auth.security.type.AuthType;
import com.github.microservice.net.ResultContent;
import com.zhongshu.card.client.model.base.IDParam;
import com.zhongshu.card.client.model.base.SortParam;
import com.zhongshu.card.client.model.scene.*;
import com.zhongshu.card.client.type.DataState;
import com.zhongshu.card.server.core.service.scene.RoleSceneInfoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * @author TRX
 * @date 2024/6/5
 */
@RestController
@RequestMapping("/roleSceneInfo")
@Tag(name = "组件--角色组件管理")
public class RoleSceneInfoController {

    @Autowired
    private RoleSceneInfoService roleSceneInfoService;


    //----------------------------------配置 start---------------------------
    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "角色绑定组件(多个)", description = "角色绑定组件（多个）")
    @RequestMapping(value = "bindScenes", method = {RequestMethod.POST})
    public ResultContent bindScenes(@RequestBody @Valid RoleBindsSceneParam param) {
        return this.roleSceneInfoService.bindScenes(param);
    }

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "角色删除组件", description = "角色删除组件")
    @RequestMapping(value = "deleteById", method = {RequestMethod.POST})
    public ResultContent deleteById(@RequestBody IDParam param) {
        return this.roleSceneInfoService.deleteById(param.getId());
    }

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "角色组件列表（列表形式）", description = "角色组件列表（列表形式）")
    @RequestMapping(value = {"list"}, method = {RequestMethod.POST})
    public ResultContent<List<RoleSceneInfoModel>> list(@RequestBody IDParam param) {
        return roleSceneInfoService.list(param.getId());
    }

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "角色组件所有（树形式）", description = "角色组件所有（树形式）")
    @RequestMapping(value = {"tree"}, method = {RequestMethod.POST})
    public ResultContent<List<RoleSceneComTreeModel>> tree(@RequestBody IDParam param) {
        return roleSceneInfoService.tree(List.of(param.getId()), null);
    }
    //----------------------------------配置 end------------------------------

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "得到角色所有已启用的组件列表", description = "得到角色所有已启用的组件列表")
    @RequestMapping(value = {"getRoleAllEnableScenes"}, method = {RequestMethod.POST})
    public ResultContent<List<RoleSceneComponentModel>> getRoleAllEnableScenes(@RequestBody IDParam param) {
        return roleSceneInfoService.listByRoleIds(List.of(param.getId()), DataState.Enable);
    }

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "得到用户所有组件", description = "得到用户所有组件")
    @RequestMapping(value = {"getUserAllEnableScenes"}, method = {RequestMethod.GET})
    public ResultContent<List<SceneInfoAboutComModel>> getUserAllEnableScenes() {
        return ResultContent.buildSuccess(roleSceneInfoService.getUserAllEnableScenes());
    }

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "根据组件数据ID 组件详情", description = "根据组件数据ID 组件详情")
    @RequestMapping(value = "getDetailById", method = {RequestMethod.POST})
    public ResultContent<RoleSceneInfoModel> getDetailById(@RequestBody IDParam param) {
        return this.roleSceneInfoService.getDetailById(param.getId());
    }

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "排序", description = "排序")
    @RequestMapping(value = "sort", method = {RequestMethod.POST})
    public ResultContent sort(@RequestBody SortParam param) {
        return this.roleSceneInfoService.sort(param);
    }

}
