package cn.iocoder.yudao.module.asset.controller.admin.station;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.asset.controller.admin.station.vo.*;
import cn.iocoder.yudao.module.asset.dal.dataobject.station.HydrogenStationDO;
import cn.iocoder.yudao.module.asset.service.station.HydrogenStationService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import java.util.List;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

/**
 * 加氢站管理 Controller
 *
 * @author 芋道源码
 */
@Tag(name = "管理后台 - 加氢站管理")
@RestController
@RequestMapping("/asset/hydrogen-station")
@Validated
public class HydrogenStationController {

    @Resource
    private HydrogenStationService hydrogenStationService;

    @PostMapping("/create")
    @Operation(summary = "创建加氢站")
    @PreAuthorize("@ss.hasPermission('asset:hydrogen-station:create')")
    public CommonResult<Long> createHydrogenStation(@Valid @RequestBody HydrogenStationSaveReqVO createReqVO) {
        return success(hydrogenStationService.createHydrogenStation(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新加氢站")
    @PreAuthorize("@ss.hasPermission('asset:hydrogen-station:update')")
    public CommonResult<Boolean> updateHydrogenStation(@Valid @RequestBody HydrogenStationSaveReqVO updateReqVO) {
        hydrogenStationService.updateHydrogenStation(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除加氢站")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('asset:hydrogen-station:delete')")
    public CommonResult<Boolean> deleteHydrogenStation(@RequestParam("id") Long id) {
        hydrogenStationService.deleteHydrogenStation(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得加氢站")
    @Parameter(name = "id", description = "编号", required = true, example = "1")
    @PreAuthorize("@ss.hasPermission('asset:hydrogen-station:query')")
    public CommonResult<HydrogenStationRespVO> getHydrogenStation(@RequestParam("id") Long id) {
        HydrogenStationDO hydrogenStation = hydrogenStationService.getHydrogenStation(id);
        return success(BeanUtils.toBean(hydrogenStation, HydrogenStationRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得加氢站分页")
    @PreAuthorize("@ss.hasPermission('asset:hydrogen-station:query')")
    public CommonResult<PageResult<HydrogenStationRespVO>> getHydrogenStationPage(@Valid HydrogenStationPageReqVO pageReqVO) {
        PageResult<HydrogenStationDO> pageResult = hydrogenStationService.getHydrogenStationPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, HydrogenStationRespVO.class));
    }

    @GetMapping("/simple-list")
    @Operation(summary = "获得加氢站精简列表", description = "用于下拉选择")
    public CommonResult<List<HydrogenStationSimpleRespVO>> getHydrogenStationSimpleList() {
        List<HydrogenStationDO> list = hydrogenStationService.getHydrogenStationSimpleList();
        return success(BeanUtils.toBean(list, HydrogenStationSimpleRespVO.class));
    }

}
