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.scene.SceneInfoAboutComModel;
import com.zhongshu.card.client.model.scene.SceneInfoModel;
import com.zhongshu.card.client.model.scene.SceneInfoParam;
import com.zhongshu.card.client.model.scene.SceneInfoSearch;
import com.zhongshu.card.client.type.DataState;
import com.zhongshu.card.server.core.service.scene.SceneInfoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
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;

/**
 * @author TRX
 * @date 2024/6/5
 */
@RestController
@RequestMapping("/sceneInfo")
@Tag(name = "场景--平台场景管理")
public class SceneInfoController {

    @Autowired
    private SceneInfoService sceneInfoService;

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "场景列表-分页查询", description = "场景列表-分页查询")
    @RequestMapping(value = {"page"}, method = {RequestMethod.POST})
    public ResultContent<Page<SceneInfoModel>> page(@Parameter(hidden = true) @PageableDefault(page = 0, size = 10) Pageable pageable, @Parameter(required = false) SceneInfoSearch param) {
        return sceneInfoService.page(param, pageable);
    }

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "添加-编辑场景", description = "添加-编辑场景")
    @RequestMapping(value = "saveInfo", method = {RequestMethod.POST})
    public ResultContent saveInfo(@RequestBody @Valid SceneInfoParam param) {
        return this.sceneInfoService.saveInfo(param);
    }

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "根据场景数据ID 场景详情", description = "根据场景数据ID 场景详情")
    @RequestMapping(value = "getDetailById", method = {RequestMethod.POST})
    public ResultContent<SceneInfoAboutComModel> getDetailById(@RequestBody IDParam param) {
        return this.sceneInfoService.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.sceneInfoService.deleteById(param.getId());
    }

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "禁用场景", description = "禁用场景")
    @RequestMapping(value = "disableData", method = {RequestMethod.POST})
    public ResultContent disableData(@RequestBody IDParam param) {
        return this.sceneInfoService.changeState(param.getId(), DataState.Disable);
    }

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "启用场景", description = "启用场景")
    @RequestMapping(value = "enableById", method = {RequestMethod.POST})
    public ResultContent enableById(@RequestBody IDParam param) {
        return this.sceneInfoService.changeState(param.getId(), DataState.Enable);
    }

    //--------------------场景的组件 start---------------------


}
