package com.njcn.advance.controller.assess;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.njcn.advance.pojo.param.assess.AssessWindLoadParamQuery;
import com.njcn.advance.pojo.po.assess.AssessWindLoadParam;
import com.njcn.advance.service.assess.IAssessWindLoadParamService;
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.common.utils.HttpResultUtil;
import com.njcn.web.factory.PageFactory;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import com.njcn.web.controller.BaseController;

import java.util.List;

/**
 * <p>
 * 风电场类负荷参数 前端控制器
 * </p>
 *
 * @author cdf
 * @since 2025-06-06
 */
@RestController
@RequestMapping("/assessWindLoadParam")
@Api(tags = "风电场类负荷参数管理")
@RequiredArgsConstructor
public class AssessWindLoadParamController extends BaseController {

    private final IAssessWindLoadParamService assessWindLoadParamService;

    @ApiOperation("获取风电场类负荷参数列表")
    @PostMapping("/list")
    public HttpResult<List<AssessWindLoadParam>> list(@RequestBody AssessWindLoadParamQuery query) {
        LambdaQueryWrapper<AssessWindLoadParam> wrapper = Wrappers.<AssessWindLoadParam>lambdaQuery()
                .like(query.getWindgeneratorName() != null, AssessWindLoadParam::getWindgeneratorName, query.getWindgeneratorName())
                .eq(query.getAssessId() != null, AssessWindLoadParam::getAssessId, query.getAssessId());
        List<AssessWindLoadParam> list = assessWindLoadParamService.list(wrapper);
        return HttpResultUtil.assembleResult(CommonResponseEnum.SUCCESS.getCode(), list,
                CommonResponseEnum.SUCCESS.getMessage());
    }

    @ApiOperation("分页查询风电场类负荷参数")
    @PostMapping("/page")
    public HttpResult<Page<AssessWindLoadParam>> page(@RequestBody AssessWindLoadParamQuery query) {
        Page<AssessWindLoadParam> pageParam = new Page<>(
                PageFactory.getPageNum(query),
                PageFactory.getPageSize(query)
        );
        LambdaQueryWrapper<AssessWindLoadParam> wrapper = Wrappers.<AssessWindLoadParam>lambdaQuery()
                .like(query.getWindgeneratorName() != null, AssessWindLoadParam::getWindgeneratorName, query.getWindgeneratorName())
                .eq(query.getAssessId() != null, AssessWindLoadParam::getAssessId, query.getAssessId());
        Page<AssessWindLoadParam> pageData = assessWindLoadParamService.page(pageParam, wrapper);
        return HttpResultUtil.assembleResult(CommonResponseEnum.SUCCESS.getCode(), pageData,
                CommonResponseEnum.SUCCESS.getMessage());
    }

    @ApiOperation("根据ID获取风电场类负荷参数详情")
    @ApiImplicitParam(name = "windgeneratorId", value = "风力发电机ID", required = true, type = "String")
    @GetMapping("/getInfo")
    public HttpResult<AssessWindLoadParam> getInfo(@RequestParam("windgeneratorId") String windgeneratorId) {
        AssessWindLoadParam param = assessWindLoadParamService.getByWindgeneratorId(windgeneratorId);
        return HttpResultUtil.assembleResult(CommonResponseEnum.SUCCESS.getCode(), param,
                CommonResponseEnum.SUCCESS.getMessage());
    }

    @ApiOperation("新增风电场类负荷参数")
    @PostMapping("/add")
    public HttpResult<Boolean> add(@RequestBody @Validated AssessWindLoadParamQuery param) {
        boolean result = assessWindLoadParamService.add(param);
        return HttpResultUtil.assembleResult(CommonResponseEnum.SUCCESS.getCode(), result,
                CommonResponseEnum.SUCCESS.getMessage());
    }

    @ApiOperation("修改风电场类负荷参数")
    @PostMapping("/edit")
    public HttpResult<Boolean> edit(@RequestBody @Validated AssessWindLoadParamQuery.UpdateAssessWindLoadParamQuery updateQuery) {
        assessWindLoadParamService.update(updateQuery);
        return HttpResultUtil.assembleResult(CommonResponseEnum.SUCCESS.getCode(), true,
                CommonResponseEnum.SUCCESS.getMessage());
    }

    @ApiOperation("删除风电场类负荷参数")
    @ApiImplicitParam(name = "windgeneratorId", value = "风力发电机ID", required = true, type = "String")
    @PostMapping("/delete")
    public HttpResult<Boolean> delete(@RequestBody List<String> windgeneratorId) {
        boolean result = assessWindLoadParamService.removeByIds(windgeneratorId);
        return HttpResultUtil.assembleResult(CommonResponseEnum.SUCCESS.getCode(), result,
                CommonResponseEnum.SUCCESS.getMessage());
    }

    @ApiOperation("根据评估用户ID查询风电场负荷参数")
    @ApiImplicitParam(name = "assessId", value = "评估用户ID", required = true, type = "String")
    @GetMapping("/listByAssessId")
    public HttpResult<List<AssessWindLoadParam>> listByAssessId(@RequestParam("assessId") String assessId) {
        List<AssessWindLoadParam> list = assessWindLoadParamService.listByAssessId(assessId);
        return HttpResultUtil.assembleResult(CommonResponseEnum.SUCCESS.getCode(), list,
                CommonResponseEnum.SUCCESS.getMessage());
    }
}