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

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.IDsParam;
import com.zhongshu.card.client.model.devices.deviceProduct.DeviceProductBindDeviceBind;
import com.zhongshu.card.client.model.devices.deviceProduct.DeviceProductBindDeviceModel;
import com.zhongshu.card.client.model.devices.deviceProduct.DeviceProductBindDeviceSearch;
import com.zhongshu.card.server.core.service.devices.deviceProduct.DeviceProductBindDeviceService;
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.util.Assert;
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;

/**
 * 产品 绑定设备
 *
 * @author TRX
 * @date 2024/6/5
 */
@RestController
@RequestMapping("/deviceProductBindDevice")
@Tag(name = "产品管理-设备绑定")
public class DeviceProductBindDeviceController {

    @Autowired
    private DeviceProductBindDeviceService deviceProductBindDeviceService;

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "绑定设备", description = "绑定设备")
    @RequestMapping(value = "bindDevices", method = {RequestMethod.POST})
    public ResultContent bindDevices(@RequestBody DeviceProductBindDeviceBind param) {
        return this.deviceProductBindDeviceService.bindDevices(param);
    }

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "移除设备(多个)", description = "移除设备(多个)")
    @RequestMapping(value = "deleteDevicesInfo", method = {RequestMethod.POST})
    public ResultContent deleteDevicesInfo(@RequestBody IDsParam param) {
        return this.deviceProductBindDeviceService.deleteDevicesInfo(param);
    }

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "设备数据列表-分页查询", description = "设备数据列表-分页查询")
    @RequestMapping(value = {"page"}, method = {RequestMethod.POST})
    public ResultContent<Page<DeviceProductBindDeviceModel>> page(
            @Parameter(hidden = true) @PageableDefault(page = 0, size = 10) Pageable pageable,
            @Parameter(required = false) DeviceProductBindDeviceSearch param) {
        Assert.hasText(param.getProjectOid(), "projectOid不能为空");
        return deviceProductBindDeviceService.page(param, pageable);
    }

}
