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

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
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.door.DoorUserInOutEventDTO;
import com.yuchen.saas.park.api.entity.door.DoorDeviceEvent;
import com.yuchen.saas.park.api.entity.door.DoorDeviceGroupItem;
import com.yuchen.saas.park.api.entity.door.DoorUserInOutEvent;
import com.yuchen.saas.park.service.service.door.DoorUserInOutEventService;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.nest.springwrap.core.mp.support.Condition;
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;

/**
 * <p>
 * 人员出入事件 前端控制器
 * </p>
 *
 * @author miaoqs
 * @since 2023-12-20
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/doorUserInOutEvent")
public class DoorUserInOutEventController {

    private final DoorUserInOutEventService userInOutEventService;

    @PostMapping("/saveOrUpdate")
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "人员出入事件 新增/修改", notes = "人员出入事件 新增/修改")
    public R saveOrUpdate(@Valid @RequestBody DoorUserInOutEvent doorUserInOutEvent) {
        if(Func.isEmpty(doorUserInOutEvent)) {
            return R.error("人员出入事件不能为空");
        }
        return R.data(userInOutEventService.saveOrUpdate(doorUserInOutEvent));
    }
    
    /**
     * 获取详情
     * @param id
     * @return
     */
    @GetMapping("/detail")
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "人员出入事件 详情", notes = "人员出入事件详情")
    public R detail(Long id) {
        return R.data(userInOutEventService.getById(id));
    }

    /**
     * 根据主表id删除人员出入事件
     * @param id
     * @return
     */
    @PostMapping("/removeId")
    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "根据主表id 人员出入事件 删除", notes = "根据主表id 人员出入事件 删除")
    public R removeId(Long id) {
        userInOutEventService.removeById(id);
        return R.success();
    }

    /**
     * 人员出入事件 分页
     */
    @PostMapping("/page")
    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "人员出入事件 分页", notes = "人员出入事件 分页")
    public R<NestPage<DoorUserInOutEvent>> page(@Valid @RequestBody DoorUserInOutEventDTO req) {
        Page<DoorUserInOutEvent> page = new Page<>();
        page.setCurrent(req.getCurrent());
        page.setSize(req.getSize());
        return  R.data(userInOutEventService.paramPage(page, req));
    }

}
