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

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.yuchen.saas.park.api.dto.door.DoorHolidayPlanDTO;
import com.yuchen.saas.park.api.dto.door.DoorPlanTemplateDTO;
import com.yuchen.saas.park.api.entity.door.DoorHolidayGroupSet;
import com.yuchen.saas.park.api.entity.door.DoorPlanTemplate;
import com.yuchen.saas.park.service.service.door.DoorPlanTemplateService;
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-15
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/doorPlanTemplate")
public class DoorPlanTemplateController {

    private final DoorPlanTemplateService doorPlanTemplateService;

    /**
     * 计划模板 新增/修改
     */
    @PostMapping("/saveOrUpdate")
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "计划模板 新增/修改", notes = "计划模板 新增/修改")
    public R saveOrUpdate(@Valid @RequestBody DoorPlanTemplateDTO doorPlanTemplateDTO) throws Exception {
        if(Func.isEmpty(doorPlanTemplateDTO)) {
            return R.error("计划模板不能为空");
        }
        return R.data(doorPlanTemplateService.saveOrUpdate(doorPlanTemplateDTO));
    }

    /**
     * 获取详情
     * @param id
     * @return
     */
    @GetMapping("/detail")
    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "计划模板详情", notes = "计划模板详情")
    public R detail(Long id) {
        return R.data(doorPlanTemplateService.detail(id));
    }

    /**
     * 根据主表id删除计划模板
     * @param id
     * @return
     */
    @PostMapping("/removeId")
    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "根据主表id计划模板删除", notes = "根据主表id计划模板删除")
    public R removeId(Long id) {
        String msg = doorPlanTemplateService.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 = doorPlanTemplateService.batchRemoveId(idList);
        if(Func.isNotEmpty(msg)){
            R.error(msg);
        }
        return R.success();
    }

    /**
     * 被访人员信息列表
     */
    @PostMapping("/List")
    @ApiOperationSupport(order = 4)
    @ApiOperation(value = "计划模板信息列表", notes = "计划模板信息列表")
    public R<List<DoorPlanTemplate>> List() {
        return R.data(doorPlanTemplateService.getList());
    }

    /**
     * 获取默认模板
     * @return
     */
    @GetMapping("/getDefault")
    @ApiOperationSupport(order = 5)
    @ApiOperation(value = "获取默认模板", notes = "获取默认模板")
    public R getDefault() {
        return R.data(doorPlanTemplateService.getDefault());
    }

    /**
     * 根据计划模板id查询假日组设置列表
     */
    @GetMapping("/getHolidayGroupSetListById")
    @ApiOperationSupport(order = 5)
    @ApiOperation(value = "根据计划模板id查询假日组设置列表", notes = "根据计划模板id查询假日组设置列表")
    public R<List<DoorHolidayGroupSet>> getHolidayGroupSetListById(Long id) {
        return R.data(doorPlanTemplateService.getHolidayGroupSetListById(id));
    }

    /**
     * 调用iot接口 配置人员权限周计划
     */
    @PostMapping("/setIotWeekPlan")
    @ApiOperationSupport(order = 6)
    @ApiOperation(value = "调用iot接口 配置人员权限周计划", notes = "调用iot接口 配置人员权限周计划")
    public R setIotWeekPlan(@Valid @RequestBody DoorHolidayPlanDTO doorHolidayPlanDTO) throws Exception {
        return R.data(doorPlanTemplateService.setIotWeekPlan(doorHolidayPlanDTO));
    }

    /**
     * 调用iot接口 配置人员权限计划模板
     */
    @PostMapping("/setIotUserRightPlanTemplate")
    @ApiOperationSupport(order = 6)
    @ApiOperation(value = "调用iot接口 配置人员权限计划模板", notes = "调用iot接口 配置人员权限计划模板")
    public R setIotUserRightPlanTemplate(@Valid @RequestBody DoorHolidayPlanDTO doorHolidayPlanDTO) throws Exception {
        return R.data(doorPlanTemplateService.setIotUserRightPlanTemplate(doorHolidayPlanDTO));
    }

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

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

}
