mod governance;
mod proposal;
mod vote;

pub use governance::*;
pub use proposal::*;
pub use vote::*;

use crate::consts::*;
use steel::*;

#[repr(u8)]
#[derive(Clone, Copy, Debug, Eq, PartialEq, IntoPrimitive, TryFromPrimitive)]
pub enum GovernanceAccount {
    Governance = 200,
    Proposal = 201,
    Vote = 202,
}

pub fn governance_pda() -> (Pubkey, u8) {
    Pubkey::find_program_address(&[GOVERNANCE], &crate::ID)
}

pub fn proposal_pda(id: u64) -> (Pubkey, u8) {
    Pubkey::find_program_address(&[PROPOSAL, &id.to_le_bytes()], &crate::ID)
}

pub fn vote_pda(proposal_id: u64, voter: Pubkey) -> (Pubkey, u8) {
    Pubkey::find_program_address(
        &[VOTE, &proposal_id.to_le_bytes(), &voter.to_bytes()],
        &crate::ID,
    )
}
