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

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.yuchen.saas.device.api.dto.IdDto;
import com.yuchen.saas.device.api.dto.IdsDto;
import com.yuchen.saas.park.api.dto.repair.SaasMatterRepairDispatchDto;
import com.yuchen.saas.park.api.entity.elevator.SaasParkElevatorMonitorAlarmRecords;
import com.yuchen.saas.park.api.request.ElevatorMonitorAlarmRecordRequest;
import com.yuchen.saas.park.api.request.ElevatorMonitorRunningStateRequest;
import com.yuchen.saas.park.api.response.ElevatorMonitorRunningStateResponse;
import com.yuchen.saas.park.api.response.SaasParkElevatorMonitorAlarmRecordsResponse;
import com.yuchen.saas.park.service.service.elevator.ISaasParkElevatorMonitorAlarmRecordsService;
import com.yuchen.saas.park.service.service.elevator.ISaasParkElevatorMonitorRunningStateService;
import com.yuchen.saas.park.service.service.repair.ISaasMatterRepairService;
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.Query;
import org.nest.springwrap.core.tool.api.R;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

/**
 * <p>
 * 梯控-电梯监测-运行状态 前端控制器
 * </p>
 *
 * @author baichaojie
 * @since 2024-06-21
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/saasParkElevatorMonitorRunningState")
@Api(value = "梯控电梯监测控制器接口", tags = "梯控电梯监测控制器接口")
public class SaasParkElevatorMonitorRunningStateController {

    private final ISaasParkElevatorMonitorRunningStateService iSaasParkElevatorMonitorService;

    private final ISaasParkElevatorMonitorAlarmRecordsService iSaasParkElevatorMonitorAlarmRecordsService;

    private final ISaasMatterRepairService baseService;


    /**
     * 梯控-电梯监测-电梯运行-运行状态分页列表
     * @param reqDTO
     * @param query
     * @return
     */
    @GetMapping("/list/page")
    @ApiOperation(value = "梯控-电梯监测-电梯运行-运行状态分页列表", notes = "梯控-电梯监测-电梯运行-运行状态分页列表")
    public R<IPage<ElevatorMonitorRunningStateResponse>> list(@Valid ElevatorMonitorRunningStateRequest reqDTO, Query query) {
        return iSaasParkElevatorMonitorService.list(reqDTO, query);
    }


    /**
     * 梯控-电梯监测-电梯告警-告警记录
     * @param reqDTO
     * @return
     */
    @GetMapping("/list/alarm")
    @ApiOperation(value = "梯控-电梯监测-电梯告警-告警记录分页", notes = "梯控-电梯监测-电梯告警-告警记录分页")
    public R<IPage<SaasParkElevatorMonitorAlarmRecordsResponse>> alarmList(@Valid ElevatorMonitorAlarmRecordRequest reqDTO, Query query) {
        return iSaasParkElevatorMonitorAlarmRecordsService.alarmList(reqDTO,query);
    }


    /**
     * 梯控-电梯监测-电梯告警-派工单
     * @param dispatchDto 受理Dto
     * @return TRUE/FALSE
     */
    @PostMapping("/dispatch")
    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "梯控-电梯监测-电梯告警-派工", notes = "梯控-电梯监测-电梯告警-派工")
    public R<Boolean> dispatch(@RequestBody @Validated SaasMatterRepairDispatchDto dispatchDto) {
        return R.data(baseService.dispatch(dispatchDto));
        //iSaasParkElevatorMonitorAlarmRecordsService.updateRepaire(dispatchDto);
        //return R.success();
    }


    /**
     * 梯控-电梯监测-电梯告警-关闭工单
     * @param idDto
     * @return
     */
    @PostMapping("/close")
    @ApiOperation(value = "梯控-电梯监测-电梯告警-关闭工单",notes = "梯控-电梯监测-电梯告警-关闭工单")
    public R close(@Valid @RequestBody IdDto idDto) {
        iSaasParkElevatorMonitorAlarmRecordsService.close(idDto);
        return R.success();
    }

    /**
     * 梯控-电梯监测-电梯告警-批量关闭工单
     * @param idsDto
     * @return
     */
    @PostMapping("/closeBatch")
    @ApiOperation(value = "梯控-电梯监测-电梯告警-批量关闭",notes = "梯控-电梯监测-电梯告警-批量关闭")
    public R closeBatch(@Valid @RequestBody IdsDto idsDto) {
        iSaasParkElevatorMonitorAlarmRecordsService.closeBatch(idsDto.getIds());
        return R.success();
    }


    /**
     * 梯控-电梯监测-电梯告警-导出
     * @param reqDTO
     * @param response
     */
    @PostMapping("/exportAlarmRecordsData")
    @ApiOperation(value = " 梯控-电梯监测-电梯告警-导出", notes = "梯控-电梯监测-电梯告警-导出")
    public void exportAlarmRecordsData(@Validated @RequestBody ElevatorMonitorAlarmRecordRequest reqDTO, HttpServletResponse response) {
        iSaasParkElevatorMonitorAlarmRecordsService.exportAlarmRecordsData(reqDTO, response);
    }



}
