package com.sonic.lion.service;

import com.sonic.lion.domain.entity.AccountBuff;
import com.sonic.lion.domain.entity.AccountBuffAwaiting;
import com.sonic.lion.domain.entity.AppleRefundRecord;
import com.sonic.lion.domain.enums.BuffType;
import com.sonic.lion.domain.enums.InOrOut;
import com.sonic.lion.domain.input.BuffChangeInput;
import com.sonic.lion.domain.input.BuffTransferInput;
import com.sonic.lion.domain.output.WalletOutput;
import org.springframework.lang.NonNull;

import java.util.List;

/**
 * @author: code
 * @date: 2025/07/16
 * @Description:
 * @version: 1.0.0
 */
public interface AccountBuffService {

    /**
     * 根据uid查询buff账户
     *
     * @param uid
     * @return
     */
    AccountBuff getByUid(Long uid);

    /**
     * 增加待入账金额
     *
     * @param input
     */
    Long addAwaitingIncome(@NonNull BuffChangeInput input);

    /**
     * 减少充值金额
     * @param uid
     * @param buff
     * @return
     */
    boolean frozenBalance(Long uid, Long buff);


    /**
     * 冻结余额 并发送消息
     *
     * @param userId
     * @param getBuffAmount
     */
    AppleRefundRecord.FronzenStatus fronzenBalanceAndSendMessage(Long userId, Long getBuffAmount);

    /**
     * 冻结钱包余额
     * @param uid
     * @param buff
     * @return
     */
    boolean unFrozenBalance(Long uid, Long buff);

    /**
     * 待入账金额入账
     *
     * @param accountBuffAwaiting
     */
    void awaitingIncomeToWithdrawableIncome(@NonNull AccountBuffAwaiting accountBuffAwaiting);

    /**
     * 转账
     * @param input
     * @return
     */
    List<Long> transfer(@NonNull BuffTransferInput input);

    /**
     * 计算总收入
     *
     * @param accountBuff
     * @return
     */
    Long calculateIncome(AccountBuff accountBuff);

    /**
     * 当提现失败 回滚 增加可提现金额
     *
     * @param input
     */
    void addWithdrawableIncome(@NonNull BuffChangeInput input);

    /**
     * 保存流水
     * @param input
     * @param accountBuff
     * @param inOrOut
     * @param buffType
     * @return
     */
    Long saveBill(BuffChangeInput input, AccountBuff accountBuff, InOrOut inOrOut, BuffType buffType);

    /**
     * 加上在途余额
     *
     * @param id
     * @param amount
     * @return
     */
    void addWithdrawOnGoing(Long id, Long amount);


    /**
     * 扣减 在途余额
     *
     * @param id
     * @param amount
     * @return
     */
    boolean decWithdrawOnGoing(Long id, Long amount);


    /**
     * 在途资金 回滚到 可提现余额
     *
     * @param id
     * @param amount
     * @return
     */
    boolean withdrawOnGoingRollback(Long id, Long amount);

    /**
     * 获取用户的钱包余额
     * @param uid
     * @return
     */
    WalletOutput wallet(Long uid);
}
