use super::{AudioCodec, ContainerFormat};
use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct QualityProfile {
    pub name: String,
    pub bitrate: u32, // en bps (ex: 320000)
    pub codec: AudioCodec,
    pub sample_rate: u32,
    pub channels: u8,
    pub container: ContainerFormat,
    pub hls_segment_time: Option<u32>, // Durée segment en secondes si HLS
}

impl QualityProfile {
    /// Profil Hi-Res : 320kbps, 48kHz, Stereo, AAC
    pub fn hi_res() -> Self {
        Self {
            name: "hi_res".to_string(),
            bitrate: 320_000,
            codec: AudioCodec::AAC,
            sample_rate: 48_000,
            channels: 2,
            container: ContainerFormat::HLS,
            hls_segment_time: Some(6),
        }
    }

    /// Profil High : 192kbps, 44.1kHz, Stereo, AAC
    pub fn high() -> Self {
        Self {
            name: "high".to_string(),
            bitrate: 192_000,
            codec: AudioCodec::AAC,
            sample_rate: 44_100,
            channels: 2,
            container: ContainerFormat::HLS,
            hls_segment_time: Some(6),
        }
    }

    /// Profil Medium : 128kbps, 44.1kHz, Stereo, AAC
    pub fn medium() -> Self {
        Self {
            name: "medium".to_string(),
            bitrate: 128_000,
            codec: AudioCodec::AAC,
            sample_rate: 44_100,
            channels: 2,
            container: ContainerFormat::HLS,
            hls_segment_time: Some(6),
        }
    }

    /// Profil Low : 64kbps, 22.05kHz, Mono, HE-AAC (simulé par AAC pour compatibilité max)
    pub fn low() -> Self {
        Self {
            name: "low".to_string(),
            bitrate: 64_000,
            codec: AudioCodec::AAC,
            sample_rate: 22_050,
            channels: 1,
            container: ContainerFormat::HLS,
            hls_segment_time: Some(6),
        }
    }

    /// Profil Mobile : 32kbps, 22.05kHz, Mono, Optimisé pour réseaux faibles
    pub fn mobile() -> Self {
        Self {
            name: "mobile".to_string(),
            bitrate: 32_000,
            codec: AudioCodec::AAC,
            sample_rate: 22_050,
            channels: 1,
            container: ContainerFormat::HLS,
            hls_segment_time: Some(4), // Plus court pour adaptation rapide
        }
    }

    /// Retourne tous les profils standards
    pub fn all_defaults() -> Vec<Self> {
        vec![Self::hi_res(), Self::high(), Self::medium(), Self::low(), Self::mobile()]
    }
}
