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

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.yuchen.saas.park.api.dto.elevator.*;
import com.yuchen.saas.park.api.entity.elevator.PmgBatParkInfoDevice;
import com.yuchen.saas.park.api.request.ElevatorPermissionGroupRequest;
import com.yuchen.saas.park.api.request.ElevatorPointGroupReq;
import com.yuchen.saas.park.api.request.ElevatorPointRequest;
import com.yuchen.saas.park.api.request.ElevatorTreeRequest;
import com.yuchen.saas.park.api.response.ElevatorPermissionGroupResponse;
import com.yuchen.saas.park.api.response.ElevatorPointResponse;
import com.yuchen.saas.park.api.vo.elevator.ElevatorPointGroupVO;
import com.yuchen.saas.park.api.vo.elevator.ElevatorTreeVO;
import com.yuchen.saas.park.service.service.elevator.ISaasParkElevatorManageLocationService;
import com.yuchen.saas.park.service.service.elevator.ISaasParkElevatorManageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.nest.springwrap.core.mp.support.NestPage;
import org.nest.springwrap.core.mp.support.Query;
import org.nest.springwrap.core.tool.api.R;
import org.nest.springwrap.core.tool.utils.Func;
import org.springframework.web.bind.annotation.*;

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

/**
 * <p>
 * 梯控-电梯管理 前端控制器
 * </p>
 *
 * @author baichaojie
 * @since 2024-06-21
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/saasParkElevatorManageController")
@Api(value = "梯控电梯管理控制器接口", tags = "梯控电梯管理控制器接口")
public class SaasParkElevatorManageController {


    private final ISaasParkElevatorManageService iSaasParkElevatorManageService;

    private final ISaasParkElevatorManageLocationService iSaasParkElevatorManageLocationService;


    /**
     * 梯控-电梯管理-电梯点-电梯点分页列表
     *
     * @param reqDTO
     * @param query
     * @return
     */
    @GetMapping("/list/getElevatorPointList")
    @ApiOperation(value = "梯控-电梯管理-电梯点-电梯点分页列表", notes = "梯控-电梯管理-电梯点-电梯点分页列表")
    public R<IPage<ElevatorPointResponse>> getElevatorPointList(@Valid ElevatorPointRequest reqDTO, Query query) {
        return iSaasParkElevatorManageLocationService.list(reqDTO, query);
    }



    /**
     * 梯控-调用IOT获取设备列表
     * 似乎没用
     * @param reqDTO
     * @param query
     * @return
     */
    @GetMapping("/list/getIotElevatorList")
    @ApiOperation(value = "梯控-调用IOT获取设备列表", notes = "梯控-调用IOT获取设备列表")
    public R<IPage<ElevatorPointResponse>> getIotElevatorList(@Valid ElevatorPointRequest reqDTO, Query query) {
        return iSaasParkElevatorManageLocationService.getIotElevatorList();
    }


    /**
     * 梯控-电梯管理-电梯点-添加/编辑
     */
    @PostMapping("/saveOrUpdate")
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "梯控-电梯管理-电梯点-添加/编辑", notes = "梯控-电梯管理-电梯点-添加/编辑")
    public R saveOrUpdate(@Valid @RequestBody ElevatorPointDTO reqDTO) {
        if (Func.isEmpty(reqDTO)) {
            return R.error("电梯点信息不能为空");
        }
        return R.status(iSaasParkElevatorManageLocationService.saveOrUpdateByParam(reqDTO));

    }





    /**
     * 梯控-电梯管理-电梯点-删除
     *
     * @param reqDTO
     * @return
     */
    @PostMapping("/removeId")
    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "梯控-电梯管理-电梯点-删除", notes = "梯控-电梯管理-电梯点-删除")
    public R removeId(@RequestBody ElevatorPointDTO reqDTO)  {
        String msg = iSaasParkElevatorManageLocationService.deleteById(reqDTO.getId());
        if (Func.isNotEmpty(msg)) {
            return R.fail(msg);
        } else {
            return R.success();
        }
    }


    /**
     * 梯控-电梯管理-权限配置-按项目查出对应分组(废弃)
     *
     * @param reqDTO
     * @param query
     * @return
     */
    @GetMapping("/list/getElevatorPermissionGroupList")
    @ApiOperation(value = "梯控-电梯管理-权限配置-按项目查出对应分组((废弃))", notes = "梯控-电梯管理-权限配置-按项目查出对应分组((废弃))")
    public R<IPage<ElevatorPermissionGroupResponse>> getElevatorPermissionGroupList(@Valid ElevatorPermissionGroupRequest reqDTO, Query query) {
        return iSaasParkElevatorManageService.getPermissionGroupList(reqDTO, query);
    }


    /**
     * 梯控-电梯管理-权限配置-新增/修改分组
     */
    @PostMapping("/saveOrUpdatePermissionGroup")
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "梯控-电梯管理-权限配置-新增/修改分组((废弃))", notes = "梯控-电梯管理-权限配置-新增/修改分组((废弃))")
    public R saveOrUpdatePermissionGroup(@Valid @RequestBody ElevatorPermissionGroupDTO elevatorPermissionGroupDTO) {
        if (Func.isEmpty(elevatorPermissionGroupDTO)) {
            return R.error("电梯权限配置不能为空");
        }
        return R.data(iSaasParkElevatorManageService.saveOrUpdatePermissionGroupByParam(elevatorPermissionGroupDTO));
    }


    /**
     * 梯控-电梯管理-电梯点-修改限制
     */
    @PostMapping("/updateElevatorLimit")
    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "梯控-电梯管理-电梯点-修改限制", notes = "梯控-电梯管理-电梯点-修改限制")
    public R updateElevatorLimit(@Valid @RequestBody SelectListDTO selectListDTO) {
        iSaasParkElevatorManageLocationService.updateElevatorLimit(selectListDTO);
        return R.success();
    }


}