//! Socket option definitions
use core::{net::SocketAddr, time::Duration};

use super::{MacAddress, SocketInterfaceQuery};

option_group!(
    #[doc = "Common socket options"]
    pub enum SocketOptionVariant<'de> {
        #[doc = "(Read-only) Local address of the socket"]
        0x1000: LocalAddress # 32 (Option<SocketAddr>),
        #[doc = "(Read-only) Remote address of the socket"]
        0x1001: PeerAddress # 32 (Option<SocketAddr>),
        #[doc = "If not [None], receive/accept operations time out after a certain amount"]
        0x1002: RecvTimeout # 32 (Option<Duration>),
        #[doc = "If not [None], send operations time out after a certain amount"]
        0x1003: SendTimeout # 32 (Option<Duration>),
        #[doc = "If not [None], connect operations time out after a certain amount"]
        0x1004: ConnectTimeout # 32 (Option<Duration>),
    }
);

option_group!(
    #[doc = "UDP socket protocol-level options"]
    pub enum UdpSocketOptionVariant<'de> {
        #[doc = "UDP unicast packet Time-to-Live"]
        0x2FFF: Ttl # 4 (u32),
        #[doc = "If `true`, allows broadcast packets to be sent from the socket"]
        0x2000: Broadcast # 4 (bool),
        #[doc = "If `true`, IPv4 multicast packets loop back to the local host"]
        0x2001: MulticastLoopV4 # 4 (bool),
        #[doc = "If `true`, IPv6 multicast packets loop back to the local host"]
        0x2002: MulticastLoopV6 # 4 (bool),
        #[doc = "Time-to-Live for IPv4 multicast packets"]
        0x2003: MulticastTtlV4 # 4 (u32),
    }
);

option_group!(
    #[doc = "TCP socket protocol-level options"]
    pub enum TcpSocketOptionVariant<'de> {
        #[doc = "If `true`, disables the Nagle's algorithm (which is not yet implemented)"]
        0x3000: NoDelay # 4 (bool),
        #[doc = "If `true`, only allows IPv6 connections to be made to a IPv6 TCP listener"]
        0x3001: Ipv6Only # 4 (bool),
    }
);

option_group!(
    #[doc = "Raw socket options"]
    pub enum RawSocketOptionVariant<'de> {
        #[doc = "
            If a raw socket is bound to an interface, it will
            receive packets from only that interface
        "]
        0xF000: BoundInterface(SocketInterfaceQuery<'de>),
        #[doc = "(Write-only) unbinds the socket from its current interface"]
        0xF001: UnbindInterface # 0 (()),
        #[doc = "(Read-only) currently bound interface's hardware address"]
        0xF002: BoundHardwareAddress # 32 (MacAddress),
    }
);
