use pumpkin_macros::packet;

use std::io::{Error, Write};

use crate::serial::PacketWrite;

#[packet(85)]
pub struct CTransfer {
    pub address: String,
    pub port: u16,
    pub reload_world: bool,
}

impl PacketWrite for CTransfer {
    fn write<W: Write>(&self, writer: &mut W) -> Result<(), Error> {
        self.address.write(writer)?;
        self.port.write(writer)?;
        self.reload_world.write(writer)?;
        // Optional GatheringsConfigurationJoinInfo.
        false.write(writer)
    }
}

impl CTransfer {
    #[must_use]
    pub const fn new(address: String, port: u16, reload_world: bool) -> Self {
        Self {
            address,
            port,
            reload_world,
        }
    }
}
