package com.starry.admin.modules.system.controller;

import com.starry.admin.modules.system.module.entity.SysTenantRechargeInfoEntity;
import com.starry.admin.modules.system.module.vo.SysTenantRechargeInfoAddVo;
import com.starry.admin.modules.system.module.vo.SysTenantRechargeInfoQueryVo;
import com.starry.admin.modules.system.service.ISysTenantRechargeInfoService;
import com.starry.common.annotation.Log;
import com.starry.common.enums.BusinessType;
import com.starry.common.result.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import javax.annotation.Resource;
import org.springframework.beans.BeanUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 租户充值信息Controller
 *
 * @author admin
 * @since 2024-09-05
 */
@Api(tags = "租户充值管理", description = "租户充值记录相关接口")
@RestController
@RequestMapping("/platform/recharge")
public class SysTenantRechargeInfoController {
    @Resource
    private ISysTenantRechargeInfoService sysTenantRechargeInfoService;

    /**
     * 查询租户充值信息列表
     */
    @ApiOperation(value = "查询充值记录", notes = "分页查询租户充值记录列表")
    @ApiResponses({
            @ApiResponse(code = 200, message = "操作成功", response = SysTenantRechargeInfoEntity.class, responseContainer = "Page")})
    // @PreAuthorize("@customSs.hasPermission('play:info:list')")
    @PostMapping("/listByPage")
    public R list(@ApiParam(value = "查询条件", required = true) @Validated @RequestBody SysTenantRechargeInfoQueryVo vo) {
        return R.ok(sysTenantRechargeInfoService.selectByPage(vo));
    }

    /**
     * 获取租户充值信息详细信息
     */
    @ApiOperation(value = "获取充值详情", notes = "根据ID获取租户充值记录详细信息")
    @ApiImplicitParam(name = "id", value = "充值记录ID", required = true, dataType = "String", paramType = "path")
    @ApiResponses({@ApiResponse(code = 200, message = "操作成功", response = SysTenantRechargeInfoEntity.class)})
    // @PreAuthorize("@customSs.hasPermission('play:info:query')")
    @GetMapping(value = "/{id}")
    public R getInfo(@PathVariable("id") String id) {
        return R.ok(sysTenantRechargeInfoService.selectSysTenantRechargeInfoById(id));
    }

    /**
     * 新增租户充值信息
     */
    @ApiOperation(value = "新增充值记录", notes = "创建租户充值记录")
    @ApiResponses({@ApiResponse(code = 200, message = "操作成功"), @ApiResponse(code = 500, message = "添加失败")})
    // @PreAuthorize("@customSs.hasPermission('play:info:create')")
    @Log(title = "租户充值信息", businessType = BusinessType.INSERT)
    @PostMapping("/create")
    public R create(
            @ApiParam(value = "充值信息", required = true) @Validated @RequestBody SysTenantRechargeInfoAddVo addVo) {
        SysTenantRechargeInfoEntity entity = new SysTenantRechargeInfoEntity();
        BeanUtils.copyProperties(addVo, entity);
        boolean success = sysTenantRechargeInfoService.create(entity);
        if (success) {
            return R.ok();
        }
        return R.error("添加失败");
    }

    /**
     * 修改租户充值信息
     */
    @ApiOperation(value = "修改充值记录", notes = "根据ID修改租户充值记录")
    @ApiImplicitParam(name = "id", value = "充值记录ID", required = true, dataType = "String", paramType = "path")
    @ApiResponses({@ApiResponse(code = 200, message = "操作成功"), @ApiResponse(code = 500, message = "修改失败")})
    @PreAuthorize("@customSs.hasPermission('play:info:edit')")
    @Log(title = "租户充值信息", businessType = BusinessType.UPDATE)
    @PostMapping(value = "/update/{id}")
    public R update(@PathVariable String id,
            @ApiParam(value = "充值信息", required = true) @RequestBody SysTenantRechargeInfoEntity sysTenantRechargeInfo) {
        sysTenantRechargeInfo.setId(id);
        boolean success = sysTenantRechargeInfoService.update(sysTenantRechargeInfo);
        if (success) {
            return R.ok();
        }
        return R.error("修改失败");
    }

    /**
     * 删除租户充值信息
     */
    @ApiOperation(value = "删除充值记录", notes = "根据ID批量删除租户充值记录")
    @ApiImplicitParam(name = "ids", value = "充值记录ID数组", required = true, dataType = "String[]", paramType = "path")
    @ApiResponses({@ApiResponse(code = 200, message = "操作成功", response = Boolean.class)})
    // @PreAuthorize("@customSs.hasPermission('play:info:remove')")
    @Log(title = "租户充值信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R remove(@PathVariable String[] ids) {
        return R.ok(sysTenantRechargeInfoService.deleteSysTenantRechargeInfoByIds(ids));
    }
}
