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.PermissionDTO;
import com.yuchen.saas.park.api.dto.elevator.SaasParkElevatorPermissionElevatorGroupDTO;
import com.yuchen.saas.park.api.request.ElevatorPointGroupReq;
import com.yuchen.saas.park.api.request.ElevatorTreeRequest;
import com.yuchen.saas.park.api.vo.elevator.ElevatorPointGroupVO;
import com.yuchen.saas.park.service.service.elevator.ISaasParkElevatorPermissionElevatorGroupService;
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.tool.api.R;
import org.nest.springwrap.core.tool.utils.Func;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 * 梯控分组 前端控制器
 * </p>
 *
 * @author baichaojie
 * @since 2024-07-08
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/saasParkElevatorPermissionElevatorGroup")
@Api(value = "梯控-电梯管理-电梯组", tags = "梯控-电梯管理-电梯组")
public class SaasParkElevatorPermissionElevatorGroupController {

    private final ISaasParkElevatorPermissionElevatorGroupService baseService;


    /**
     * 分页 梯控分组
     */
    @GetMapping("/page")
    @ApiOperationSupport(order = 5)
    @ApiOperation(value = "分页 梯控分组", notes = "分页 梯控分组")
    public R<NestPage<ElevatorPointGroupVO>> page(ElevatorPointGroupReq req) {
        Page<ElevatorPointGroupReq> page = new Page<>();
        page.setCurrent(req.getCurrent());
        page.setSize(req.getSize());
        IPage<ElevatorPointGroupVO> pages = baseService.pageByParam(page, req);
        return R.data(NestPage.of(pages));
    }






    /**
     * 分页 梯控分组设备树
     */
    @GetMapping("/tree")
    @ApiOperationSupport(order = 5)
    @ApiOperation(value = "梯控分组设备树", notes = "梯控分组设备树")
    public R<NestPage<PermissionDTO>> tree(ElevatorTreeRequest req) {
        Page<ElevatorTreeRequest> page = new Page<>();
        page.setCurrent(1);
        page.setSize(10000);
        IPage<PermissionDTO> pages = baseService.tree(page, req);
        return R.data(NestPage.of(pages));
    }



    /**
     * 电梯分组 新增/修改
     */
    @PostMapping("/saveOrUpdate")
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "电梯分组 新增/修改", notes = "电梯分组 新增/修改")
    public R saveOrUpdate(@Valid @RequestBody SaasParkElevatorPermissionElevatorGroupDTO pointGroupDTO) {
        if(Func.isEmpty(pointGroupDTO)) {
            return R.error("电梯分组不能为空");
        }
        return R.data(baseService.saveOrUpdateByParam(pointGroupDTO));
    }

    /**
     * 获取详情
     * @param id
     * @return
     */
    @GetMapping("/detail")
    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "电梯分组详情", notes = "电梯分组详情")
    public R detail(Long id) {
        return R.data(baseService.detailById(id));
    }

    /**
     * 根据主表id删除电梯分组
     * @param pointGroupDTO
     * @return
     */
    @PostMapping("/removeId")
    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "根据主表id电梯分组删除", notes = "根据主表id电梯分组删除")
    public R removeId(@RequestBody SaasParkElevatorPermissionElevatorGroupDTO pointGroupDTO) throws Exception {
        return R.data(baseService.deleteById(pointGroupDTO.getId()));
    }






}
