package com.njcn.relational.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.njcn.relational.pojo.po.SGConPlantB;
import com.njcn.relational.service.SGConPlantBService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/plant")
@RequiredArgsConstructor
public class SGConPlantBController {

    private final SGConPlantBService sgConPlantBService;

    /**
     * 新增场站
     */
    @PostMapping("/add")
    public Boolean add(@RequestBody SGConPlantB entity) {
        return sgConPlantBService.save(entity);
    }

    /**
     * 根据ID删除
     */
    @DeleteMapping("/remove/{id}")
    public Boolean remove(@PathVariable String id) {
        return sgConPlantBService.removeById(id);
    }

    /**
     * 批量删除
     */
    @DeleteMapping("/batch")
    public Boolean batchRemove(@RequestBody List<String> idList) {
        return sgConPlantBService.removeByIds(idList);
    }

    /**
     * 修改场站
     */
    @PutMapping("/update")
    public Boolean update(@RequestBody SGConPlantB entity) {
        return sgConPlantBService.updateById(entity);
    }

    /**
     * 根据ID查询单条
     */
    @GetMapping("/get/{id}")
    public SGConPlantB getById(@PathVariable String id) {
        return sgConPlantBService.getById(id);
    }

    /**
     * 分页查询
     */
    @GetMapping("/page")
    public IPage<SGConPlantB> page(
            @RequestParam(defaultValue = "1") long pageNum,
            @RequestParam(defaultValue = "10") long pageSize,
            SGConPlantB query
    ) {
        Page<SGConPlantB> page = new Page<>(pageNum, pageSize);
        LambdaQueryWrapper<SGConPlantB> wrapper = new LambdaQueryWrapper<>();
        // 可根据业务自行拼接模糊/等值条件示例
        wrapper.like(query.getName() != null, SGConPlantB::getName, query.getName());
        wrapper.eq(query.getPlantType() != null, SGConPlantB::getPlantType, query.getPlantType());
        wrapper.eq(query.getConnectivePgId() != null, SGConPlantB::getConnectivePgId, query.getConnectivePgId());
        return sgConPlantBService.page(page, wrapper);
    }

    /**
     * 查询全部列表（不分页）
     */
    @GetMapping("/list")
    public List<SGConPlantB> list(SGConPlantB query) {
        LambdaQueryWrapper<SGConPlantB> wrapper = new LambdaQueryWrapper<>();
        wrapper.like(query.getName() != null, SGConPlantB::getName, query.getName());
        return sgConPlantBService.list(wrapper);
    }
}