#![allow(dead_code)]

use crate::io::{self, BorrowedCursor, IoSlice, IoSliceMut};
use crate::net::{Shutdown, SocketAddr};
use crate::os::yggdrasil::io::{AsFd, AsRawFd, BorrowedFd, RawFd};
use crate::sys::io::FileDesc;
use crate::sys_common::{AsInner, FromInner, IntoInner};
use crate::time::Duration;

pub use crate::sys::{cvt, cvt_r};

pub use super::yggdrasil_rt::netc;

pub type wrlen_t = usize;

#[derive(Debug)]
pub struct Socket(FileDesc);

impl Socket {
    pub fn new(_addr: &SocketAddr, _ty: i32) -> io::Result<Socket> {
        todo!()
    }

    pub fn connect_timeout(&self, _addr: &SocketAddr, _timeout: Duration) -> io::Result<()> {
        todo!()
    }

    pub fn set_linger(&self, _linger: Option<Duration>) -> io::Result<()> {
        todo!()
    }

    pub fn read_buf(&self, _buf: BorrowedCursor<'_>) -> io::Result<()> {
        todo!()
    }

    pub fn linger(&self) -> io::Result<Option<Duration>> {
        todo!()
    }

    pub fn shutdown(&self, _how: Shutdown) -> io::Result<()> {
        todo!()
    }

    pub fn read(&self, _buf: &mut [u8]) -> io::Result<usize> {
        todo!()
    }

    pub fn accept(
        &self,
        _storage: *mut netc::sockaddr,
        _len: *mut netc::socklen_t,
    ) -> io::Result<Self> {
        todo!()
    }

    pub fn duplicate(&self) -> io::Result<Self> {
        todo!()
    }

    #[inline]
    pub fn is_read_vectored(&self) -> bool {
        todo!()
    }

    pub fn recv_from(&self, _buf: &mut [u8]) -> io::Result<(usize, SocketAddr)> {
        todo!()
    }

    pub fn write(&self, _buf: &[u8]) -> io::Result<usize> {
        todo!()
    }

    pub fn write_vectored(&self, _bufs: &[IoSlice<'_>]) -> io::Result<usize> {
        todo!()
    }

    pub fn is_write_vectored(&self) -> bool {
        todo!()
    }

    pub fn set_timeout(&self, _dur: Option<Duration>, _kind: i32) -> io::Result<()> {
        todo!()
    }

    pub fn timeout(&self, _kind: i32) -> io::Result<Option<Duration>> {
        todo!()
    }

    pub fn set_nodelay(&self, _nodelay: bool) -> io::Result<()> {
        todo!()
    }

    pub fn nodelay(&self) -> io::Result<bool> {
        todo!()
    }

    pub fn take_error(&self) -> io::Result<Option<io::Error>> {
        todo!()
    }

    pub fn set_nonblocking(&self, _nonblocking: bool) -> io::Result<()> {
        todo!()
    }

    pub fn peek_from(&self, _buf: &mut [u8]) -> io::Result<(usize, SocketAddr)> {
        todo!()
    }

    pub fn peek(&self, _buf: &mut [u8]) -> io::Result<usize> {
        todo!()
    }

    pub fn read_vectored(&self, _bufs: &mut [IoSliceMut<'_>]) -> io::Result<usize> {
        todo!()
    }

    pub fn as_raw(&self) -> RawFd {
        self.0.as_raw_fd()
    }
}

impl AsInner<FileDesc> for Socket {
    fn as_inner(&self) -> &FileDesc {
        &self.0
    }
}

impl IntoInner<FileDesc> for Socket {
    fn into_inner(self) -> FileDesc {
        self.0
    }
}

impl FromInner<FileDesc> for Socket {
    fn from_inner(fd: FileDesc) -> Self {
        Self(fd)
    }
}

impl AsFd for Socket {
    fn as_fd(&self) -> BorrowedFd<'_> {
        self.0.as_fd()
    }
}

impl AsRawFd for Socket {
    fn as_raw_fd(&self) -> RawFd {
        self.0.as_raw_fd()
    }
}

pub fn init() {
    todo!();
}

pub fn cvt_gai(_err: i32) -> io::Result<()> {
    unimplemented!("No networking support");
}
