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

import com.github.microservice.auth.security.annotations.ResourceAuth;
import com.github.microservice.auth.security.type.AuthType;
import com.zhongshu.card.client.model.devices.GateWayInfoModel;
import com.zhongshu.card.client.model.devices.GateWayInfoParam;
import com.zhongshu.card.client.model.devices.GateWayInfoSearch;
import com.github.microservice.net.ResultContent;
import com.zhongshu.card.client.service.school.GateWayInfoService;
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.*;

import java.util.List;

/**
 * 网关
 *
 * @author TRX
 * @date 2024/6/5
 */
@RestController
@RequestMapping("/gateWays")
@Tag(name = "平台-网关管理")
public class GateWayInfoController {

    @Autowired
    GateWayInfoService gateWayInfoService;

    //----------------------------基础信息 start------------------------

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "根据网关ID 查询详情", description = "根据网关ID 查询详情 ")
    @RequestMapping(value = "getGateWayInfo", method = {RequestMethod.GET})
    public ResultContent<GateWayInfoModel> getGateWayInfo(@RequestParam(name = "gateWayId") String gateWayId) {
        return this.gateWayInfoService.getGateWayInfo(gateWayId);
    }

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "编辑网关的区域", description = "编辑网关的区域")
    @RequestMapping(value = "updateGateArea", method = {RequestMethod.POST})
    public ResultContent updateGateArea(@RequestBody GateWayInfoParam param) {
        return this.gateWayInfoService.updateGateArea(param);
    }

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

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "得到所有的网关", description = "得到所有的网关")
    @RequestMapping(value = "getAllGateWayInfo", method = {RequestMethod.GET})
    public ResultContent<List<GateWayInfoModel>> getAllGateWayInfo() {
        return this.gateWayInfoService.getAllGateWayInfo();
    }

    //----------------------------基础信息 end--------------------------

}
