use crate::message2::Msg02RDAStatusData;
use crate::message31::Message31;
use crate::NexradParseError;

pub const MSG_RDA_PERFORMANCE_DATA: u8 = 3;
pub const MSG_RDA_VOLUME_COVERAGE_DATA: u8 = 5;
pub const MSG_RDA_CLUTTER_FILTER_BYPASS_MAP: u8 = 13;
pub const MSG_RDA_CLUTTER_MAP_DATA: u8 = 15;
pub const MSG_RDA_ADAPTABLE_PARAMETERS: u8 = 18;
pub const MSG_MODEL_DATA_MESSAGE: u8 = 29;
pub const MSG_DIGITAL_RADAR_DATA_GENERIC: u8 = 31;

pub const LEGACY_CTM_HEADER_LEN: usize = 12;
pub const MESSAGE_HEADER_SIZE: usize = 16;
pub const DEFAULT_MESSAGE_SIZE: usize = 2432;
pub const MESSAGE_BODY_SIZE: usize = DEFAULT_MESSAGE_SIZE - LEGACY_CTM_HEADER_LEN - MESSAGE_HEADER_SIZE;

#[derive(Debug)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct MessageHeader {
    pub message_size: u16,
    pub rda_redundant_channel: u8,
    pub message_type: u8,
    pub message_sequence_number: u16,
    pub julian_date: u16,
    pub millis_after_midnight: u32,
    pub num_of_message_segments: u16,
    pub message_segment_num: u16,
}

pub trait FromBody<const BODY_SIZE: usize> {
    fn from_body(body: [u8; BODY_SIZE]) -> Result<Self, NexradParseError> where Self: Sized;
}

#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum Message {
    Msg02(Msg02RDAStatusData),
    Msg31(Message31)
}