use solana_sdk::{
    instruction::{AccountMeta, Instruction},
    pubkey::Pubkey,
};

use crate::constants::Discriminator;
use crate::types::SwitchCurveParams;

/// Build a SwitchPriceCurve instruction (discriminator 11).
///
/// Accounts (2): authority(signer), curveMeta(w).
pub fn build_switch_price_curve(
    authority: &Pubkey,
    curve_meta_pda: &Pubkey,
    params: &SwitchCurveParams,
    program_id: &Pubkey,
) -> Instruction {
    let data = vec![
        Discriminator::SwitchPriceCurve as u8,
        params.side as u8,
        params.slot,
    ];

    let keys = vec![
        AccountMeta::new_readonly(*authority, true),
        AccountMeta::new(*curve_meta_pda, false),
    ];

    Instruction {
        program_id: *program_id,
        accounts: keys,
        data,
    }
}

/// Build a SwitchRiskCurve instruction (discriminator 12).
///
/// Accounts (2): authority(signer), curveMeta(w).
pub fn build_switch_risk_curve(
    authority: &Pubkey,
    curve_meta_pda: &Pubkey,
    params: &SwitchCurveParams,
    program_id: &Pubkey,
) -> Instruction {
    let data = vec![
        Discriminator::SwitchRiskCurve as u8,
        params.side as u8,
        params.slot,
    ];

    let keys = vec![
        AccountMeta::new_readonly(*authority, true),
        AccountMeta::new(*curve_meta_pda, false),
    ];

    Instruction {
        program_id: *program_id,
        accounts: keys,
        data,
    }
}
