package org.dromara.system.controller.system;



import cn.dev33.satoken.annotation.SaIgnore;
import jakarta.validation.constraints.NotNull;
import org.dromara.common.core.domain.R;

import lombok.RequiredArgsConstructor;
import org.dromara.system.service.IUserTransferService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;



@Validated
@RestController
@RequestMapping("/system/user/balance")
@RequiredArgsConstructor
public class SysUserBalanceController {

    private final IUserTransferService sysUserService;

    /**
     * 余额转冻结
     */
    @PostMapping("/transfer/balanceToFreeze")
    @SaIgnore
    public R<Void> balanceToFreeze(@NotNull(message = "转出用户ID不能为空") Long fromUserId,
                                   @NotNull(message = "转入用户ID不能为空") Long toUserId,
                                   @NotNull(message = "金额不能为空") Long amount) {
        boolean result = sysUserService.transferBalanceToFreeze(fromUserId, toUserId, amount);
        return result ? R.ok("转账成功") : R.fail("转账失败");
    }

    /**
     * 冻结转余额
     */
    @PostMapping("/transfer/freezeToBalance")
    @SaIgnore
    public R<Void> freezeToBalance(@NotNull(message = "转出用户ID不能为空") Long fromUserId,
                                   @NotNull(message = "转入用户ID不能为空") Long toUserId,
                                   @NotNull(message = "金额不能为空") Long amount) {
        boolean result = sysUserService.transferFreezeToBalance(fromUserId, toUserId, amount);
        return result ? R.ok("转账成功") : R.fail("转账失败");
    }
}
