use core::cmp::Ordering;

use rapira::Rapira;
use serde::{Deserialize, Serialize};

#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq, Rapira)]
pub struct ValueWithId {
    #[rapira(with = rapira::byte_rapira)]
    pub id: u8,
    pub value: Value,
}

impl PartialOrd for ValueWithId {
    fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
        Some(self.id.cmp(&other.id))
    }
}

impl From<(u8, Value)> for ValueWithId {
    fn from(value: (u8, Value)) -> Self {
        ValueWithId {
            id: value.0,
            value: value.1,
        }
    }
}

#[derive(PartialEq, Clone, Serialize, Deserialize, Debug, Eq, Rapira)]
#[repr(u8)]
pub enum List {
    Bool(Vec<bool>),
    U64(Vec<u64>),
    I64(Vec<i64>),
    // Decimal(Vec<Decimal>),
    Str(Vec<String>),
    Pair(Vec<ValueWithId>),
    List(Vec<List>),
}

#[derive(PartialEq, Clone, Serialize, Deserialize, Debug, Eq, Rapira)]
#[rapira(static_size = None)]
#[rapira(min_size = 1)]
#[repr(u8)]
pub enum Value {
    Void,
    Bool(bool),
    U64(u64),
    I64(i64),
    // Decimal(Decimal),
    Str(String),
    Pair(Box<ValueWithId>),
    List(List),
}
