package com.njcn.device.pq.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.njcn.common.pojo.annotation.OperateInfo;
import com.njcn.common.pojo.enums.common.DataStateEnum;
import com.njcn.common.pojo.enums.common.LogEnum;
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.common.utils.HttpResultUtil;
import com.njcn.device.line.service.LineService;
import com.njcn.device.pq.enums.LineBaseEnum;
import com.njcn.device.pq.pojo.param.PqSubstationExpendParam;
import com.njcn.device.pq.pojo.po.Line;
import com.njcn.device.pq.pojo.po.PqSubstationExpend;
import com.njcn.device.pq.pojo.po.Substation;
import com.njcn.device.pq.pojo.vo.PqSubstationExpendVO;
import com.njcn.device.pq.service.ISubstationService;
import com.njcn.device.pq.service.PqSubstationExpendService;
import com.njcn.device.pq.service.impl.SubstationServiceImpl;
import com.njcn.web.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 变电站扩展信息 CRUD
 *
 * @Author: cdf
 * @CreateTime: 2026-07-29
 * @Description: 变电站扩展信息增删改查
 */
@Slf4j
@Api(tags = "变电站扩展信息")
@RestController
@RequestMapping("/substationExpend")
@RequiredArgsConstructor
public class PqSubstationExpendController extends BaseController {

    private final PqSubstationExpendService pqSubstationExpendService;




    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @GetMapping("/getById")
    @ApiOperation("根据ID查询变电站扩展信息")
    @ApiImplicitParam(name = "id", value = "变电站ID", required = true)
    public HttpResult<PqSubstationExpendVO> getById(@RequestParam("id") String id) {
        String methodDescribe = getMethodDescribe("getById");
        PqSubstationExpendVO vo = pqSubstationExpendService.getByIdVO(id);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, vo, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @GetMapping("/list")
    @ApiOperation("查询变电站扩展信息列表")
    public HttpResult<List<PqSubstationExpendVO>> list() {
        String methodDescribe = getMethodDescribe("list");
        List<PqSubstationExpendVO> list = pqSubstationExpendService.listVO();
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/page")
    @ApiOperation("分页查询变电站扩展信息（支持多条件过滤，含地市和名称）")
    @ApiImplicitParam(name = "param", value = "分页查询参数", required = true)
    public HttpResult<IPage<PqSubstationExpendVO>> page(@RequestBody PqSubstationExpendParam param) {
        String methodDescribe = getMethodDescribe("page");
        Page<PqSubstationExpendVO> page = pqSubstationExpendService.pageJoin(new Page<>(param.getPageNum(), param.getPageSize()), param);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, page, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/save")
    @ApiOperation("新增或修改变电站扩展信息")
    @ApiImplicitParam(name = "expend", value = "变电站扩展信息实体", required = true)
    public HttpResult<Boolean> save(@RequestBody @Validated PqSubstationExpendParam param) {
        String methodDescribe = getMethodDescribe("save");
        boolean result = pqSubstationExpendService.save(param);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/delete")
    @ApiOperation("根据ID删除变电站扩展信息")
    @ApiImplicitParam(name = "id", value = "变电站ID", required = true)
    public HttpResult<Boolean> delete(@RequestParam("id") String id) {
        String methodDescribe = getMethodDescribe("delete");
        boolean result = pqSubstationExpendService.removeById(id);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }
}