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

import com.github.microservice.net.ResultContent;
import com.zhongshu.card.client.openApi.model.DeviceInfoOpenApiModel;
import com.zhongshu.card.client.openApi.model.DevicePermissOpenApiModel;
import com.zhongshu.card.client.openApi.params.*;
import com.zhongshu.card.client.type.DataState;
import com.zhongshu.card.server.core.service.openAPI.DevicePermissOpenApiService;
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.data.domain.Page;
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 java.util.List;

/**
 * @author TRX
 * @date 2024/6/5
 */
@RestController
@RequestMapping("/openAPI/v1/devicePermiss")
@Tag(name = "openAPI-设备权限管理")
public class DevicePermissOpenApiController {

    @Autowired
    private DevicePermissOpenApiService devicePermissOpenApiService;

    @Operation(summary = "设备列表-分页查询", description = "设备列表-分页查询")
    @RequestMapping(value = {"page"}, method = {RequestMethod.POST})
    public ResultContent<Page<DeviceInfoOpenApiModel>> page(@RequestBody DeviceInfoOpenApiSearch param) {
        return devicePermissOpenApiService.page(param);
    }

    @Operation(summary = "设备详情--根据设备ID查询", description = "设备详情-根据设备ID查询")
    @RequestMapping(value = {"getDetailByDeviceId"}, method = {RequestMethod.POST})
    public ResultContent<DeviceInfoOpenApiModel> getDetailByDeviceId(@RequestBody DeviceIdParam param) {
        return devicePermissOpenApiService.getDetailByDeviceId(param);
    }

    @Operation(summary = "查询设备的权限", description = "查询设备的权限")
    @RequestMapping(value = {"getDevicePermissByDeviceId"}, method = {RequestMethod.POST})
    public ResultContent<List<DevicePermissOpenApiModel>> getDevicePermissByDeviceId(@RequestBody DeviceIdAndProjectCodeParam param) {
        return devicePermissOpenApiService.getDevicePermissByDeviceId(param);
    }

    @Operation(summary = "查询用户的设备权限", description = "查询用户的设备权限")
    @RequestMapping(value = {"getDevicePermissByUserId"}, method = {RequestMethod.POST})
    public ResultContent<List<DevicePermissOpenApiModel>> getDevicePermissByUserId(@RequestBody UserOpenApiParam param) {
        return devicePermissOpenApiService.getDevicePermissByUserId(param);
    }

    @Operation(summary = "启用权限", description = "启用权限")
    @RequestMapping(value = {"enablePermiss"}, method = {RequestMethod.POST})
    public ResultContent enablePermiss(@RequestBody PermissChangeOpenApiParam param) {
        return devicePermissOpenApiService.changePermissState(param, DataState.Enable);
    }

    @Operation(summary = "禁用权限", description = "禁用权限")
    @RequestMapping(value = {"disablePermiss"}, method = {RequestMethod.POST})
    public ResultContent disablePermiss(@RequestBody PermissChangeOpenApiParam param) {
        return devicePermissOpenApiService.changePermissState(param, DataState.Disable);
    }

    @Operation(summary = "移除设备权限", description = "移除设备权限")
    @RequestMapping(value = {"deletePermiss"}, method = {RequestMethod.POST})
    public ResultContent deletePermiss(@RequestBody PermissChangeOpenApiParam param) {
        return devicePermissOpenApiService.deletePermiss(param);
    }

    @Operation(summary = "添加用户设备权限", description = "添加用户设备权限")
    @RequestMapping(value = {"addPermiss"}, method = {RequestMethod.POST})
    public ResultContent addPermiss(@RequestBody PermissChangeOpenApiParam param) {
        return devicePermissOpenApiService.addPermiss(param);
    }

}
