//! This code was AUTOGENERATED using the kinobi library.
//! Please DO NOT EDIT THIS FILE, instead use visitors
//! to add features, then rerun kinobi to update it.
//!
//! [https://github.com/metaplex-foundation/kinobi]
//!

use borsh::{BorshDeserialize, BorshSerialize};
use solana_program::pubkey::Pubkey;

#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
pub struct Group {
    pub discriminator: u8,
    pub bump: u8,
    #[cfg_attr(
        feature = "serde",
        serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
    )]
    pub id: Pubkey,
    #[cfg_attr(
        feature = "serde",
        serde(with = "serde_with::As::<Vec<serde_with::DisplayFromStr>>")
    )]
    pub members: Vec<Pubkey>,
}

impl Group {
    /// Prefix values used to generate a PDA for this account.
    ///
    /// Values are positional and appear in the following order:
    ///
    ///   0. `Group::PREFIX`
    ///   1. id (`Pubkey`)
    pub const PREFIX: &'static [u8] = "group:".as_bytes();

    pub fn create_pda(
        id: Pubkey,
        bump: u8,
    ) -> Result<solana_program::pubkey::Pubkey, solana_program::pubkey::PubkeyError> {
        solana_program::pubkey::Pubkey::create_program_address(
            &["group:".as_bytes(), id.as_ref(), &[bump]],
            &super::MAGICBLOCK_PERMISSION_PROGRAM_ID,
        )
    }

    pub fn find_pda(id: &Pubkey) -> (Pubkey, u8) {
        solana_program::pubkey::Pubkey::find_program_address(
            &["group:".as_bytes(), id.as_ref()],
            &super::MAGICBLOCK_PERMISSION_PROGRAM_ID,
        )
    }
}
