package com.zsElectric.boot.business.controller;

import com.zsElectric.boot.business.service.RechargeLevelService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zsElectric.boot.business.model.form.RechargeLevelForm;
import com.zsElectric.boot.business.model.query.RechargeLevelQuery;
import com.zsElectric.boot.business.model.vo.RechargeLevelVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zsElectric.boot.core.web.PageResult;
import com.zsElectric.boot.core.web.Result;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import jakarta.validation.Valid;

/**
 * 充值档位信息前端控制层
 *
 * @author zsElectric
 * @since 2025-12-12 14:47
 */
@Tag(name = "充值档位信息接口")
@RestController
@RequestMapping("/api/v1/recharge-level")
@RequiredArgsConstructor
public class RechargeLevelController  {

    private final RechargeLevelService rechargeLevelService;

    @Operation(summary = "充值档位信息分页列表")
    @GetMapping("/page")
    @PreAuthorize("@ss.hasPerm('business:recharge-level:query')")
    public PageResult<RechargeLevelVO> getRechargeLevelPage(RechargeLevelQuery queryParams ) {
        IPage<RechargeLevelVO> result = rechargeLevelService.getRechargeLevelPage(queryParams);
        return PageResult.success(result);
    }

    @Operation(summary = "新增充值档位信息")
    @PostMapping
    @PreAuthorize("@ss.hasPerm('business:recharge-level:add')")
    public Result<Void> saveRechargeLevel(@RequestBody @Valid RechargeLevelForm formData ) {
        boolean result = rechargeLevelService.saveRechargeLevel(formData);
        return Result.judge(result);
    }

    @Operation(summary = "获取充值档位信息表单数据")
    @GetMapping("/{id}/form")
    @PreAuthorize("@ss.hasPerm('business:recharge-level:edit')")
    public Result<RechargeLevelForm> getRechargeLevelForm(
        @Parameter(description = "充值档位信息ID") @PathVariable Long id
    ) {
        RechargeLevelForm formData = rechargeLevelService.getRechargeLevelFormData(id);
        return Result.success(formData);
    }

    @Operation(summary = "修改充值档位信息")
    @PutMapping(value = "/{id}")
    @PreAuthorize("@ss.hasPerm('business:recharge-level:edit')")
    public Result<Void> updateRechargeLevel(
            @Parameter(description = "充值档位信息ID") @PathVariable Long id,
            @RequestBody @Validated RechargeLevelForm formData
    ) {
        boolean result = rechargeLevelService.updateRechargeLevel(id, formData);
        return Result.judge(result);
    }

    @Operation(summary = "删除充值档位信息")
    @DeleteMapping("/{ids}")
    @PreAuthorize("@ss.hasPerm('business:recharge-level:delete')")
    public Result<Void> deleteRechargeLevels(
        @Parameter(description = "充值档位信息ID，多个以英文逗号(,)分割") @PathVariable String ids
    ) {
        boolean result = rechargeLevelService.deleteRechargeLevels(ids);
        return Result.judge(result);
    }
}
