package com.pm.web.controller.subsystem;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.pm.common.annotation.Log;
import com.pm.common.core.controller.BaseController;
import com.pm.common.core.domain.AjaxResult;
import com.pm.common.enums.BusinessType;
import com.pm.common.config.PageData;
import com.pm.subsystem.service.ILightingService;
import com.pm.common.core.page.TableDataInfo;

/**
 * 照明系统Controller
 * 
 * @author pm
 * @date 2025-01-01
 */
@RestController
@RequestMapping("/subsystem/lighting")
public class LightingController extends BaseController
{
    @Autowired
    private ILightingService lightingService;

    /**
     * 查询照明设备列表
     */
    @PreAuthorize("@ss.hasPermi('subsystem:lighting:list')")
    @GetMapping("/device/list")
    public TableDataInfo deviceList()
    {
        PageData pd = this.getPageData();
        startPage();
        List<PageData> list = lightingService.selectLightingDeviceList(pd);
        return getDataTable(list);
    }

    /**
     * 控制照明设备
     */
    @PreAuthorize("@ss.hasPermi('subsystem:lighting:control')")
    @Log(title = "照明控制", businessType = BusinessType.UPDATE)
    @PostMapping("/device/control")
    public AjaxResult controlDevice(@RequestBody PageData pd)
    {
        return toAjax(lightingService.controlLightingDevice(pd));
    }

    /**
     * 批量控制照明
     */
    @PreAuthorize("@ss.hasPermi('subsystem:lighting:control')")
    @Log(title = "批量照明控制", businessType = BusinessType.UPDATE)
    @PostMapping("/device/batchControl")
    public AjaxResult batchControl(@RequestBody PageData pd)
    {
        return toAjax(lightingService.batchControlLighting(pd));
    }

    /**
     * 查询照明报警列表
     */
    @PreAuthorize("@ss.hasPermi('subsystem:lighting:alarm')")
    @GetMapping("/alarm/list")
    public TableDataInfo alarmList()
    {
        PageData pd = this.getPageData();
        startPage();
        List<PageData> list = lightingService.selectLightingAlarmList(pd);
        return getDataTable(list);
    }

    /**
     * 处理照明报警
     */
    @PreAuthorize("@ss.hasPermi('subsystem:lighting:alarm')")
    @Log(title = "处理照明报警", businessType = BusinessType.UPDATE)
    @PostMapping("/alarm/handle")
    public AjaxResult handleAlarm(@RequestBody PageData pd)
    {
        return toAjax(lightingService.handleLightingAlarm(pd));
    }

    /**
     * 查询照明计划列表
     */
    @PreAuthorize("@ss.hasPermi('subsystem:lighting:schedule')")
    @GetMapping("/schedule/list")
    public TableDataInfo scheduleList()
    {
        PageData pd = this.getPageData();
        startPage();
        List<PageData> list = lightingService.selectLightingScheduleList(pd);
        return getDataTable(list);
    }

    /**
     * 新增照明计划
     */
    @PreAuthorize("@ss.hasPermi('subsystem:lighting:schedule')")
    @Log(title = "照明计划", businessType = BusinessType.INSERT)
    @PostMapping("/schedule")
    public AjaxResult addSchedule(@RequestBody PageData pd)
    {
        return toAjax(lightingService.insertLightingSchedule(pd));
    }

    /**
     * 修改照明计划
     */
    @PreAuthorize("@ss.hasPermi('subsystem:lighting:schedule')")
    @Log(title = "照明计划", businessType = BusinessType.UPDATE)
    @PutMapping("/schedule")
    public AjaxResult editSchedule(@RequestBody PageData pd)
    {
        return toAjax(lightingService.updateLightingSchedule(pd));
    }

    /**
     * 删除照明计划
     */
    @PreAuthorize("@ss.hasPermi('subsystem:lighting:schedule')")
    @Log(title = "照明计划", businessType = BusinessType.DELETE)
    @DeleteMapping("/schedule/{id}")
    public AjaxResult removeSchedule(@PathVariable Long id)
    {
        return toAjax(lightingService.deleteLightingSchedule(id));
    }
}