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

import com.github.microservice.auth.client.constant.AuthConstant;
import com.github.microservice.auth.security.annotations.ResourceAuth;
import com.github.microservice.auth.security.type.AuthType;
import com.zhongshu.card.client.model.base.IDParam;
import com.zhongshu.card.client.model.devices.DeviceBindModel;
import com.zhongshu.card.client.model.devices.DeviceBindParam;
import com.zhongshu.card.client.model.devices.DeviceBindSearch;
import com.github.microservice.net.ResultContent;
import com.zhongshu.card.client.service.school.DeviceBindService;
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.*;

/**
 * 设备
 *
 * @author TRX
 * @date 2024/6/5
 */
@RestController
@RequestMapping("/school/device")
@Tag(name = "学校-设备管理")
public class DeviceBindController {

    @Autowired
    DeviceBindService deviceBindService;

    //----------------------------设备基础信息 start------------------------

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

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

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "添加-编辑设备", description = "添加-编辑设备")
    @RequestMapping(value = "addDeviceInfo", method = {RequestMethod.POST})
    public ResultContent addDeviceInfo(@RequestBody DeviceBindParam param) {
        return this.deviceBindService.addDeviceBind(param);
    }

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "删除设备", description = "删除设备")
    @RequestMapping(value = "deleteDeviceInfo", method = {RequestMethod.POST})
    public ResultContent deleteDeviceInfo(@RequestBody IDParam param) {
        return this.deviceBindService.deleteById(param.getId());
    }

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "用户所在的商户设备列表-分页查询", description = "用户所在的商户设备列表-分页查询")
    @RequestMapping(value = {"busDevicePage"}, method = {RequestMethod.POST})
    public ResultContent<Page<DeviceBindModel>> busDevicePage(
            @Parameter(hidden = true) @PageableDefault(page = 0, size = 10) Pageable pageable,
            @Parameter(required = false) DeviceBindSearch param) {
        return deviceBindService.page(param, pageable);
    }

    //----------------------------设备基础信息 end--------------------------

}
