package com.yuchen.saas.park.service.controller.security;


import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.thinkunion.sdk.iot.bean.api.CallingDeviceServiceResponse;
import com.yuchen.saas.manage.system.api.param.CommonIdParam;
import com.yuchen.saas.park.api.entity.security.SaasParkElectronicFence;
import com.yuchen.saas.park.service.service.security.ISaasParkElectronicFenceCallService;
import com.yuchen.saas.park.service.service.security.ISaasParkElectronicFenceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.nest.springwrap.core.tool.api.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 电子围栏设备表 前端控制器
 * </p>
 *
 * @author 洪铭铭
 * @since 2024-08-29
 */
@Api(tags = "电子围栏管理")
@RestController
@RequestMapping("/saasParkElectronicFence")
public class SaasParkElectronicFenceController {

    @Autowired
    private ISaasParkElectronicFenceService saasParkElectronicFenceService;

    @Autowired
    private ISaasParkElectronicFenceCallService saasParkElectronicFenceCallService;

    @PostMapping("/save")
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "新增", notes = "电子围栏新增")
    public R save(@Valid @RequestBody SaasParkElectronicFence saasParkElectronicFence) {
        return R.status(saasParkElectronicFenceService.save(saasParkElectronicFence));
    }

    @PostMapping("/list")
    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "列表", notes = "电子围栏列表")
    public R<List<SaasParkElectronicFence>> list() {
        return R.data(saasParkElectronicFenceService.getAll());
    }

    @PostMapping("/update")
    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "修改", notes = "电子围栏修改")
    public R update(@Valid @RequestBody SaasParkElectronicFence saasParkElectronicFence) {
        return R.status(saasParkElectronicFenceService.saveOrUpdate(saasParkElectronicFence));
    }

    @PostMapping("/delete")
    @ApiOperationSupport(order = 4)
    @ApiOperation(value = "删除", notes = "电子围栏删除")
    public R delete(@Valid @RequestBody CommonIdParam param) {
        return R.data(saasParkElectronicFenceService.removeById(param.getId()));
    }

    @GetMapping("/detail")
    @ApiOperationSupport(order = 5)
    @ApiOperation(value = "详情", notes = "电子围栏详情")
    public R<SaasParkElectronicFence> detail(@RequestParam("id") Long id) {
        return R.data(saasParkElectronicFenceService.getById(id));
    }

    @GetMapping("/deviceAction")
    @ApiOperationSupport(order = 6)
    @ApiOperation(value = "详情", notes = "电子围栏设备控制")
    public R<CallingDeviceServiceResponse> deviceAction(@RequestParam("id") Long id, @RequestParam("action") String action) {

        SaasParkElectronicFence fence = saasParkElectronicFenceService.getById(id);
        return R.data(saasParkElectronicFenceCallService.deviceAction(fence, action));
    }

    @GetMapping("/channelAction")
    @ApiOperationSupport(order = 7)
    @ApiOperation(value = "详情", notes = "电子围栏防区控制")
    public R<CallingDeviceServiceResponse> channelAction(@RequestParam("id") Long id, @RequestParam("action") String action) {
        SaasParkElectronicFence fence = saasParkElectronicFenceService.getById(id);
        return R.data(saasParkElectronicFenceCallService.channelAction(fence, action));
    }


//    @PostMapping("/page")
//    @ApiOperationSupport(order = 6)
//    @ApiOperation(value = "分页列表", notes = "应急预案分页列表")
//    public R<Page<SaasParkElectronicFence>> page(@RequestBody SaasParkElectronicFenceQueryDto saasParkElectronicFenceQueryDto) {
//        return R.data(saasParkElectronicFenceService.page(saasParkElectronicFenceQueryDto));
//    }

}
