use crate::claimable::{BenefitSource, CircuitRole};
use codec::{Decode, Encode};
use frame_support::dispatch::DispatchResult;
use scale_info::TypeInfo;
use sp_runtime::DispatchError;
use sp_std::{fmt::Debug, prelude::*};
pub type ExecutionId = u64;
#[derive(Encode, Decode, Clone, PartialEq, Eq, Debug, TypeInfo)]
pub struct Settlement<Account, Balance, AssetId> {
pub requester: Account,
pub recipient: Account,
pub settlement_amount: Balance,
pub maybe_asset_id: Option<AssetId>,
pub outcome: Outcome,
pub source: BenefitSource,
pub role: CircuitRole,
}
#[derive(Encode, Decode, Clone, PartialEq, Eq, Debug, TypeInfo)]
pub struct RequestCharge<Account, Balance, AssetId> {
pub payee: Account,
pub offered_reward: Balance,
pub maybe_asset_id: Option<AssetId>,
pub charge_fee: Balance,
pub recipient: Option<Account>,
pub source: BenefitSource,
pub role: CircuitRole,
}
#[derive(Encode, Decode, Clone, PartialEq, Eq, Debug, TypeInfo)]
pub enum Outcome {
UnexpectedFailure,
Revert,
Commit,
Slash,
}
pub trait AccountManager<Account, Balance, Hash, BlockNumber, AssetId> {
fn get_charge_or_fail(
charge_id: Hash,
) -> Result<RequestCharge<Account, Balance, AssetId>, DispatchError>;
fn no_charge_or_fail(charge_id: Hash) -> Result<(), DispatchError>;
fn get_settlement(charge_id: Hash) -> Option<Settlement<Account, Balance, AssetId>>;
fn get_settlements_by_role(
role: CircuitRole,
) -> Vec<(Account, Settlement<Account, Balance, AssetId>)>;
fn bump_contracts_registry_nonce() -> Result<Hash, DispatchError>;
fn validate_deposit(
charge_id: Hash,
request_charge: RequestCharge<Account, Balance, AssetId>,
) -> Result<Balance, DispatchError>;
fn deposit_batch(batch: &[(Hash, RequestCharge<Account, Balance, AssetId>)]) -> DispatchResult;
fn deposit(
charge_id: Hash,
request_charge: RequestCharge<Account, Balance, AssetId>,
) -> DispatchResult;
fn finalize(
charge_id: Hash,
outcome: Outcome,
maybe_recipient: Option<Account>,
maybe_actual_fees: Option<Balance>,
) -> DispatchResult;
fn finalize_infallible(charge_id: Hash, outcome: Outcome) -> bool;
fn cancel_deposit(charge_id: Hash) -> bool;
fn assign_deposit(charge_id: Hash, recipient: &Account) -> bool;
fn transfer_deposit(
charge_id: Hash,
new_charge_id: Hash,
new_reward: Option<Balance>,
new_payee: Option<&Account>,
new_recipient: Option<&Account>,
) -> DispatchResult;
fn can_withdraw(beneficiary: &Account, amount: Balance, asset_id: Option<AssetId>) -> bool;
fn deposit_immediately(beneficiary: &Account, amount: Balance, asset_id: Option<AssetId>);
fn withdraw_immediately(
beneficiary: &Account,
amount: Balance,
asset_id: Option<AssetId>,
) -> DispatchResult;
}