//! 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 crate::generated::types::Descriminator;
use crate::generated::types::IssuanceStatus;
use borsh::BorshDeserialize;
use borsh::BorshSerialize;
use solana_program::pubkey::Pubkey;

#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Issuance {
    pub discriminator: Descriminator,
    #[cfg_attr(
        feature = "serde",
        serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
    )]
    pub parent_bond: Pubkey,
    pub status: IssuanceStatus,
    pub version: u8,
    pub padding0: [u8; 1],
    pub interest_rate_bps: i16,
    pub padding1: [u8; 2],
    pub estimated_start_datetime: i64,
    pub actual_start_datetime: i64,
    pub liquidity: u64,
    pub requested_redemptions: u64,
    pub starting_token_amount: u64,
    pub ending_token_amount: u64,
    pub length_in_seconds: i64,
}

impl Issuance {
    pub const LEN: usize = 96;

    #[inline(always)]
    pub fn from_bytes(data: &[u8]) -> Result<Self, std::io::Error> {
        let mut data = data;
        Self::deserialize(&mut data)
    }
}

impl<'a> TryFrom<&solana_program::account_info::AccountInfo<'a>> for Issuance {
    type Error = std::io::Error;

    fn try_from(
        account_info: &solana_program::account_info::AccountInfo<'a>,
    ) -> Result<Self, Self::Error> {
        let mut data: &[u8] = &(*account_info.data).borrow();
        Self::deserialize(&mut data)
    }
}
