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

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.yuchen.saas.park.api.dto.door.DoorHolidayGroupDTO;
import com.yuchen.saas.park.api.dto.door.DoorHolidayGroupPlanDTO;
import com.yuchen.saas.park.api.dto.door.DoorHolidayPlanDTO;
import com.yuchen.saas.park.api.entity.door.DoorHolidayGroup;
import com.yuchen.saas.park.service.service.door.DoorHolidayGroupService;
import com.yuchen.saas.park.service.service.door.DoorHolidayGroupSetService;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
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 miaoqs
 * @since 2023-12-14
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/doorHolidayGroup")
public class DoorHolidayGroupController {

    private final DoorHolidayGroupService holidayGroupService;

    /**
     * 节假日组 新增/修改
     */
    @PostMapping("/saveOrUpdate")
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "节假日组 新增/修改", notes = "节假日组 新增/修改")
    public R saveOrUpdate(@Valid @RequestBody DoorHolidayGroupDTO doorHolidayGroupDTO) {
        if(Func.isEmpty(doorHolidayGroupDTO)) {
            return R.error("节假日组不能为空");
        }
        return R.data(holidayGroupService.saveOrUpdate(doorHolidayGroupDTO));
    }

    /**
     * 获取详情
     * @param id
     * @return
     */
    @GetMapping("/detail")
    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "节假日组详情", notes = "节假日组详情")
    public R detail(Long id) {
        return R.data(holidayGroupService.detail(id));
    }

    /**
     * 根据主表id删除节假日组
     * @param id
     * @return
     */
    @PostMapping("/removeId")
    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "根据主表id节假日组删除", notes = "根据主表id节假日组删除")
    public R removeId(Long id) {
        String msg = holidayGroupService.deleteById(id);
        if(Func.isNotEmpty(msg)){
            return R.error(msg);
        }
        return R.success();
    }

    /**
     * 批量删除-根据主表id删除计划模板
     * @param idList
     * @return
     */
    @PostMapping("/batchRemoveId")
    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "批量删除-根据主表id节假日组删除", notes = "批量删除-根据主表id节假日组删除")
    public R batchRemoveId(@RequestBody List<Long> idList) {
        String msg = holidayGroupService.batchRemoveId(idList);
        if(Func.isNotEmpty(msg)){
            return R.error(msg);
        }
        return R.success();
    }

    /**
     * 节假日组信息列表
     */
    @PostMapping("/List")
    @ApiOperationSupport(order = 4)
    @ApiOperation(value = "节假日组信息列表", notes = "节假日组信息列表")
    public R<List<DoorHolidayGroup>> List() {
        return R.data(holidayGroupService.getList());
    }

    /**
     * 调用iot接口 配置人员权限假日计划
     */
    @PostMapping("/setIotHolidayPlan")
    @ApiOperationSupport(order = 5)
    @ApiOperation(value = "调用iot接口 配置人员权限假日计划", notes = "调用iot接口 配置人员权限假日计划")
    public R setIotHolidayPlan(@Valid @RequestBody DoorHolidayPlanDTO doorHolidayPlanDTO) throws Exception {
        if(Func.isEmpty(doorHolidayPlanDTO)) {
            return R.error("节假日组不能为空");
        }
        return R.data(holidayGroupService.setIotHolidayPlan(doorHolidayPlanDTO));
    }

    /**
     * 调用iot接口 配置人员权限假日组
     */
    @PostMapping("/setIotHolidayGroupPlan")
    @ApiOperationSupport(order = 6)
    @ApiOperation(value = "调用iot接口 配置人员权限假日组", notes = "调用iot接口 配置人员权限假日组")
    public R setIotHolidayGroupPlan(@Valid @RequestBody DoorHolidayPlanDTO doorHolidayPlanDTO) throws Exception {
        if(Func.isEmpty(doorHolidayPlanDTO)) {
            return R.error("节假日组不能为空");
        }
        return R.data(holidayGroupService.setIotHolidayGroupPlan(doorHolidayPlanDTO));
    }

    /**
     * 调用iot接口 获取人员权限假日组
     */
    @PostMapping("/getIotHolidayGroupPlan")
    @ApiOperationSupport(order = 6)
    @ApiOperation(value = "调用iot接口 获取人员权限假日组", notes = "调用iot接口 获取人员权限假日组")
    public R getHolidayGroupPlan(@Valid @RequestBody DoorHolidayPlanDTO doorHolidayPlanDTO) throws Exception {
        if(Func.isEmpty(doorHolidayPlanDTO)) {
            return R.error("节假日组id不能为空");
        }
        return R.data(holidayGroupService.getHolidayGroupPlan(doorHolidayPlanDTO));
    }

    /**
     * 调用iot接口 获取人员权限假日计划
     */
    @PostMapping("/getIotHolidayPlan")
    @ApiOperationSupport(order = 6)
    @ApiOperation(value = "调用iot接口 获取人员权限假日计划", notes = "调用iot接口 获取人员权限假日计划")
    public R getIotHolidayPlan(@Valid @RequestBody DoorHolidayPlanDTO doorHolidayPlanDTO) throws Exception {
        if(Func.isEmpty(doorHolidayPlanDTO)) {
            return R.error("id不能为空");
        }
        return R.data(holidayGroupService.getIotHolidayPlan(doorHolidayPlanDTO));
    }

}
