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

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.base.IDsParam;
import com.zhongshu.card.client.model.visitor.setting.VisitorSettingDeviceParam;
import com.zhongshu.card.client.model.visitor.setting.VisitorSettingDeviceModel;
import com.zhongshu.card.client.model.visitor.setting.VisitorSettingDeviceSearch;
import com.zhongshu.card.server.core.service.visitor.VisitorSettingDeviceService;
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("/visitorSettingDevice")
@Tag(name = "访客管理-关联设备")
public class VisitorSettingDeviceController {

    @Autowired
    private VisitorSettingDeviceService visitorSettingDeviceService;

    //-----------------------------关联的设备信息 start--------------------

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

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

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

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

    //-----------------------------关联的设备信息 end----------------------

}
