use frame_support::{pallet_prelude::*, storage::PrefixIterator};
use sp_runtime::{
    traits::{AtLeast32BitUnsigned, Member},
    DispatchResult,
};

pub trait NetworkDataBasicHandler {
    type NetworkId: Parameter
        + Member
        + AtLeast32BitUnsigned
        + Default
        + Copy
        + TypeInfo
        + MaybeSerializeDeserialize
        + MaxEncodedLen;
}

pub trait NetworkDataInspectHandler<Network>: NetworkDataBasicHandler {
    fn get(n: &Self::NetworkId) -> Option<Network>;
    fn iter() -> PrefixIterator<(Self::NetworkId, Network)>;
    fn is_nullification_period() -> bool;
}

pub trait NetworkDataMutateHandler<Network, Balance>: NetworkDataInspectHandler<Network> {
    fn register(chain_id: Self::NetworkId, network: Network) -> DispatchResult;
    fn remove(chain_id: Self::NetworkId) -> DispatchResult;

    fn increase_gatekeeper_amount(
        chain_id: &Self::NetworkId,
        amount: &Balance,
    ) -> Result<Balance, ()>;
    fn decrease_gatekeeper_amount(
        chain_id: &Self::NetworkId,
        amount: &Balance,
    ) -> Result<Balance, ()>;

    fn accumulate_outgoing_imbalance(amount: &Balance) -> Result<Balance, ()>;
    fn accumulate_incoming_imbalance(amount: &Balance) -> Result<Balance, ()>;

    fn accumulate_commission(commission: &Balance) -> Result<Balance, ()>;
    fn nullify_commission();
    fn trigger_nullification();
}
