use crate::event::EventData;

use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, Debug)]
pub enum ServerMessage {
    Event(EventData),
}

#[derive(Serialize, Deserialize, Debug, Default)]
pub enum WindowType {
    #[default]
    Default,
    Reservation(u32),
}

#[derive(Serialize, Deserialize, Debug, Default)]
pub struct CreateWindowInfo {
    pub ty: WindowType,
}

#[derive(Serialize, Deserialize, Debug)]
pub enum ClientMessage {
    ClientHello,
    CreateWindow(CreateWindowInfo),
    BlitWindow {
        window_id: u32,
        x: u32,
        y: u32,
        w: u32,
        h: u32,
    },
    DestroyWindow(u32),
    SubscribeToWindowManagement,
}

impl From<(u32, ServerMessage)> for EventData {
    fn from((_, msg): (u32, ServerMessage)) -> Self {
        let ServerMessage::Event(ev) = msg;

        ev
    }
}
