package com.usky.iot.controller.web;


import com.usky.common.core.bean.ApiResult;
import com.usky.common.core.bean.CommonPage;
import com.usky.common.log.annotation.Log;
import com.usky.common.log.enums.BusinessType;
import com.usky.iot.domain.BaseGgpFacility;
import com.usky.iot.domain.BaseScreen;
import com.usky.iot.domain.DmpDeviceInfo;
import com.usky.iot.service.BaseGgpFacilityService;
import com.usky.iot.service.BaseScreenService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author han
 * @since 2026-01-20
 */
@RestController
@RequestMapping("/baseScreen")
public class BaseScreenController {
    @Autowired
    private BaseScreenService baseScreenService;

    /**
     * 新增
     * @param baseScreen
     * @return
     */
    @PostMapping("/add")
    public ApiResult<Void> add(@RequestBody BaseScreen baseScreen) {
        baseScreenService.add(baseScreen);
        return ApiResult.success();
    }

    /**
     * 修改
     * @param baseScreen
     * @return
     */
    @PutMapping("/edit")
    public ApiResult<Void> edit(@RequestBody BaseScreen baseScreen) {
        baseScreenService.update(baseScreen);
        return ApiResult.success();
    }

    /**
     * 关联设备查看分页
     * @param screenGroup  设备ID
     * @param id  设施主键ID
     * @return
     */
    @Log(title = "大屏查看列表", businessType = BusinessType.OTHER)
    @GetMapping("/screenList")
    public ApiResult<List<BaseScreen>> screenList(@RequestParam(value = "screenGroup", required = false) Integer screenGroup,
                                                  @RequestParam(value = "id", required = false) Integer id) {
        return ApiResult.success(baseScreenService.screenList(screenGroup, id));
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @Log(title = "删除大屏", businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}")
    public ApiResult<Void> remove(@PathVariable("id") Integer id) {
        try {
            return baseScreenService.removeById(id) ? ApiResult.success() : ApiResult.error("删除失败！");
        } catch (Exception e) {
            return ApiResult.error("删除失败：" + e.getMessage());
        }
    }
}

