//! Persisted plugin parameters exposed to the DAW.

use std::sync::Arc;

use cagire_project::Project;
use nih_plug::prelude::*;
use nih_plug_egui::EguiState;
use parking_lot::Mutex;

/// DAW-visible parameters and persisted editor/project state.
#[derive(Params)]
pub struct CagireParams {
    #[persist = "editor-state"]
    pub editor_state: Arc<EguiState>,

    #[persist = "project"]
    pub project: Arc<Mutex<Project>>,

    #[id = "tempo"]
    pub tempo: FloatParam,

    #[id = "sync"]
    pub sync_to_host: BoolParam,

    #[id = "bank"]
    pub bank: IntParam,

    #[id = "pattern"]
    pub pattern: IntParam,
}

impl Default for CagireParams {
    fn default() -> Self {
        Self {
            editor_state: EguiState::from_size(1200, 800),
            project: Arc::new(Mutex::new(Project::default())),

            tempo: FloatParam::new("Tempo", 120.0, FloatRange::Linear { min: 40.0, max: 300.0 })
                .with_unit(" BPM")
                .with_step_size(0.1),

            sync_to_host: BoolParam::new("Sync to Host", true),

            bank: IntParam::new("Bank", 0, IntRange::Linear { min: 0, max: 31 }),

            pattern: IntParam::new("Pattern", 0, IntRange::Linear { min: 0, max: 31 }),
        }
    }
}
