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.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;

    @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 = {"getRoleAllEnableScenes"}, method = {RequestMethod.POST})
    public ResultContent<List<SceneInfoAboutComModel>> getRoleAllEnableScenes(@RequestBody IDParam param) {
        return ResultContent.buildSuccess(roleSceneInfoService.getAllEnableScenes(param.getId()));
    }

    @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 = "角色绑定场景", description = "角色绑定场景")
    @RequestMapping(value = "bindScene", method = {RequestMethod.POST})
    public ResultContent bindScene(@RequestBody @Valid RoleBindSceneParam param) {
        return this.roleSceneInfoService.bindScene(param);
    }

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "一次绑定多个（以前的删除）", description = "一次绑定多个（以前的删除）")
    @RequestMapping(value = "bindList", method = {RequestMethod.POST})
    public ResultContent bindList(@RequestBody @Valid RoleBindAllParam param) {
        return this.roleSceneInfoService.bindList(param);
    }

    @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 = "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 = "sort", method = {RequestMethod.POST})
    public ResultContent sort(@RequestBody SortParam param) {
        return this.roleSceneInfoService.sort(param);
    }

}
