Repository: juspay/hyperswitch
File: crates/api_models/src/admin.rs (Rust)

Code before:

        *webhook_version = other.webhook_version.or(webhook_version.take());
        *webhook_username = other.webhook_username.or(webhook_username.take());
        *webhook_password = other.webhook_password.or(webhook_password.take());
        *webhook_url = other.webhook_url.or(webhook_url.take());
        *payment_created_enabled = other
            .payment_created_enabled
            .or(payment_created_enabled.take());
        *payment_succeeded_enabled = other
            .payment_succeeded_enabled
            .or(payment_succeeded_enabled.take());
        *payment_failed_enabled = other
            .payment_failed_enabled
            .or(payment_failed_enabled.take());
        *payment_statuses_enabled = other
            .payment_statuses_enabled
            .or(payment_statuses_enabled.take());
        *refund_statuses_enabled = other
            .refund_statuses_enabled
            .or(refund_statuses_enabled.take());
        #[cfg(feature = "payouts")]
        {
            *payout_statuses_enabled = other
                .payout_statuses_enabled
                .or(payout_statuses_enabled.take());
        }
    }

    fn validate_statuses<T>(statuses: &[T], status_type_name: &str) -> Result<(), String>
    where
        T: strum::IntoEnumIterator + Copy + PartialEq + std::fmt::Debug,
        T: Into<Option<api_enums::EventType>>,
    {
        let valid_statuses: Vec<T> = T::iter().filter(|s| (*s).into().is_some()).collect();

        for status in statuses {
            if !valid_statuses.contains(status) {
                return Err(format!(
                    "Invalid {status_type_name} webhook status provided: {status:?}"
                ));
            }
        }
        Ok(())
    }

    pub fn validate(&self) -> Result<(), String> {
        if let Some(payment_statuses) = &self.payment_statuses_enabled {
            Self::validate_statuses(payment_statuses, "payment")?;
        }

        if let Some(refund_statuses) = &self.refund_statuses_enabled {

Review comment (suggestion):
Please avoid mutable objects.
```suggestion
        let Self {
            webhook_version: other.webhook_version.or(webhook_version),
            ..
        }
```

Code after:
                .payment_statuses_enabled
                .or(self.payment_statuses_enabled),
            refund_statuses_enabled: other
                .refund_statuses_enabled
                .or(self.refund_statuses_enabled),
            #[cfg(feature = "payouts")]
            payout_statuses_enabled: other
                .payout_statuses_enabled
                .or(self.payout_statuses_enabled),
        }
    }

    fn validate_statuses<T>(statuses: &[T], status_type_name: &str) -> Result<(), String>
    where
        T: strum::IntoEnumIterator + Copy + PartialEq + std::fmt::Debug,
        T: Into<Option<api_enums::EventType>>,
    {
        let valid_statuses: Vec<T> = T::iter().filter(|s| (*s).into().is_some()).collect();

        for status in statuses {
            if !valid_statuses.contains(status) {
                return Err(format!(
                    "Invalid {status_type_name} webhook status provided: {status:?}"
                ));
            }
        }
        Ok(())
    }

    pub fn validate(&self) -> Result<(), String> {
        if let Some(payment_statuses) = &self.payment_statuses_enabled {
            Self::validate_statuses(payment_statuses, "payment")?;
        }

        if let Some(refund_statuses) = &self.refund_statuses_enabled {
            Self::validate_statuses(refund_statuses, "refund")?;
        }

        #[cfg(feature = "payouts")]
        {
            if let Some(payout_statuses) = &self.payout_statuses_enabled {
                Self::validate_statuses(payout_statuses, "payout")?;
            }
        }

        Ok(())
    }
}

#[derive(Debug, Serialize, ToSchema)]
pub struct MerchantAccountDeleteResponse {