//! 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 crate::types::FarmType;
use crate::types::FixedPoint;
use crate::types::Token;
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 Farm {
    pub pool: Pubkey,
    pub tokens: [Pubkey; 3],
    pub token_accounts: [Pubkey; 3],
    pub supply: [Token; 3],
    pub supply_left: [Token; 3],
    pub accumulated_seconds_per_share: FixedPoint,
    pub offset_seconds_per_share: FixedPoint,
    pub start_time: u64,
    pub end_time: u64,
    pub last_update: u64,
    pub bump: u8,
    pub farm_type: FarmType,
}

impl Farm {
    pub fn decode(data: &[u8]) -> Option<Self> {
        if data.len() < 8 {
            return None;
        }
        let discriminator = &data[0..8];
        if discriminator != [161, 156, 211, 253, 250, 64, 53, 250] {
            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
    }
}
