//! This code was AUTOGENERATED using the Codama library.
//! Please DO NOT EDIT THIS FILE, instead use visitors
//! to add features, then rerun Codama to update it.
//!
//! <https://github.com/codama-idl/codama>
//!

use carbon_core::borsh::{self, BorshDeserialize};
use solana_pubkey::Pubkey;

#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(
    Debug,
    Clone,
    carbon_core::borsh::BorshSerialize,
    carbon_core::borsh::BorshDeserialize,
    PartialEq,
)]
pub struct State {
    pub admin: Pubkey,
    pub program_authority: Pubkey,
    pub bump: u8,
    pub nonce: u8,
}

impl State {
    pub fn decode(data: &[u8]) -> Option<Self> {
        if data.len() < 8 {
            return None;
        }
        let discriminator = &data[0..8];
        if discriminator != [216, 146, 107, 94, 104, 75, 182, 177] {
            return None;
        }

        let mut data_slice = data;

        data_slice = &data_slice[8..];

        if let Ok(decoded) = Self::deserialize(&mut data_slice) {
            return Some(decoded);
        }

        None
    }
}
