use candid::{CandidType, Deserialize, Nat};
use num_bigint::BigUint;
use serde::Serialize;

use crate::{SerdeWalletRegisterId, WalletRegisterId};

pub type SerdeSecretVaultSetting = SerdeServiceScopeSetting;
pub type SerdeBalanceVaultSetting = SerdeServiceScopeSetting;
pub type SerdeWalletRegistrySetting = SerdeServiceScopeSetting;
pub type SecretVaultSetting = ServiceScopeSetting;
pub type BalanceVaultSetting = ServiceScopeSetting;
pub type WalletRegistrySetting = ServiceScopeSetting;

#[derive(CandidType, Debug, Clone, Deserialize, PartialEq, Eq)]
pub struct ServiceScopeSetting {
    pub wallet_start_id: WalletRegisterId,
    pub max_wallet_count: Nat,
}

#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)]
pub struct SerdeServiceScopeSetting {
    pub wallet_start_id: SerdeWalletRegisterId,
    pub max_wallet_count: BigUint,
}

impl From<ServiceScopeSetting> for SerdeServiceScopeSetting {
    fn from(setting: ServiceScopeSetting) -> Self {
        SerdeServiceScopeSetting {
            wallet_start_id: setting.wallet_start_id.0,
            max_wallet_count: setting.max_wallet_count.into(),
        }
    }
}

impl From<SerdeServiceScopeSetting> for ServiceScopeSetting {
    fn from(setting: SerdeServiceScopeSetting) -> Self {
        ServiceScopeSetting {
            wallet_start_id: setting.wallet_start_id.into(),
            max_wallet_count: setting.max_wallet_count.into(),
        }
    }
}
