#![allow(unused_qualifications)]
use crate::{pallet, AssetIdOf, BalanceOf};
use frame_system::pallet_prelude::*;
use parity_scale_codec::{Decode, Encode, HasCompact, MaxEncodedLen};
use scale_info::TypeInfo;
use sp_runtime::{DispatchResult, Percent};
#[derive(Encode, Decode, Debug, Clone, PartialEq, Eq, MaxEncodedLen, TypeInfo)]
#[scale_info(skip_type_params(T))]
#[codec(mel_bound(T: pallet::Config))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct PaymentDetail<T: pallet::Config> {
pub asset: AssetIdOf<T>,
#[codec(compact)]
pub amount: BalanceOf<T>,
#[codec(compact)]
pub incentive_amount: BalanceOf<T>,
pub state: PaymentState<T>,
pub resolver_account: T::AccountId,
pub fee_detail: Option<(T::AccountId, BalanceOf<T>)>,
}
#[derive(Encode, Decode, Debug, Clone, PartialEq, Eq, MaxEncodedLen, TypeInfo)]
#[scale_info(skip_type_params(T))]
#[codec(mel_bound(T: pallet::Config))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum PaymentState<T: pallet::Config> {
Created,
NeedsReview,
RefundRequested { cancel_block: BlockNumberFor<T> },
PaymentRequested,
}
pub trait PaymentHandler<T: pallet::Config> {
fn create_payment(
from: &T::AccountId,
to: &T::AccountId,
asset: AssetIdOf<T>,
amount: BalanceOf<T>,
payment_state: PaymentState<T>,
incentive_percentage: Percent,
remark: Option<&[u8]>,
) -> Result<PaymentDetail<T>, sp_runtime::DispatchError>;
fn reserve_payment_amount(from: &T::AccountId, to: &T::AccountId, payment: PaymentDetail<T>) -> DispatchResult;
fn settle_payment(from: &T::AccountId, to: &T::AccountId, recipient_share: Percent) -> DispatchResult;
fn get_payment_details(from: &T::AccountId, to: &T::AccountId) -> Option<PaymentDetail<T>>;
}
pub trait DisputeResolver<Account> {
fn get_resolver_account() -> Account;
}
pub trait FeeHandler<T: pallet::Config> {
fn apply_fees(
from: &T::AccountId,
to: &T::AccountId,
detail: &PaymentDetail<T>,
remark: Option<&[u8]>,
) -> (T::AccountId, Percent);
}
#[derive(PartialEq, Eq, Clone, Encode, Decode, Debug, TypeInfo, MaxEncodedLen)]
pub enum Task {
Cancel,
}
#[derive(PartialEq, Eq, Clone, Encode, Decode, Debug, TypeInfo, MaxEncodedLen)]
pub struct ScheduledTask<Time: HasCompact> {
pub task: Task,
pub when: Time,
}