use core::ffi::{c_int, c_uchar, c_uint};

pub type cc_t = c_uchar;
pub type speed_t = c_uint;
pub type tcflag_t = c_uint;

// c_iflag
pub const IGNBRK: tcflag_t = 1 << 0;
pub const BRKINT: tcflag_t = 1 << 1;
pub const IGNPAR: tcflag_t = 1 << 2;
pub const PARMRK: tcflag_t = 1 << 3;
pub const INPCK: tcflag_t = 1 << 4;
pub const ISTRIP: tcflag_t = 1 << 5;
pub const INLCR: tcflag_t = 1 << 6;
pub const IGNCR: tcflag_t = 1 << 7;
pub const ICRNL: tcflag_t = 1 << 8;
pub const IXON: tcflag_t = 1 << 9;
pub const IXANY: tcflag_t = 1 << 10;
pub const IXOFF: tcflag_t = 1 << 11;

// c_oflag
pub const OPOST: tcflag_t = 1 << 0;
pub const ONLCR: tcflag_t = 1 << 1;
pub const OCRNL: tcflag_t = 1 << 2;
pub const ONOCR: tcflag_t = 1 << 3;
pub const ONLRET: tcflag_t = 1 << 4;
pub const OFILL: tcflag_t = 1 << 5;
pub const OFDEL: tcflag_t = 1 << 6;

// c_cflag
pub const CS5: tcflag_t = 0x0;
pub const CS6: tcflag_t = 0x1;
pub const CS7: tcflag_t = 0x2;
pub const CS8: tcflag_t = 0x3;

pub const CSIZE: tcflag_t = 0x3;
pub const CSTOPB: tcflag_t = 1 << 2;
pub const CREAD: tcflag_t = 1 << 3;
pub const PARENB: tcflag_t = 1 << 4;
pub const PARODD: tcflag_t = 1 << 5;
pub const HUPCL: tcflag_t = 1 << 6;
pub const CLOCAL: tcflag_t = 1 << 7;

// c_lflag
pub const ISIG: tcflag_t = 1 << 0;
pub const ICANON: tcflag_t = 1 << 1;
pub const ECHO: tcflag_t = 1 << 2;
pub const ECHOE: tcflag_t = 1 << 3;
pub const ECHOK: tcflag_t = 1 << 4;
pub const ECHONL: tcflag_t = 1 << 5;
pub const NOFLSH: tcflag_t = 1 << 6;
pub const TOSTOP: tcflag_t = 1 << 7;
pub const IEXTEN: tcflag_t = 1 << 8;

// c_cc
pub const VEOF: usize = 0;
pub const VEOL: usize = 1;
pub const VERASE: usize = 2;
pub const VINTR: usize = 3;
pub const VKILL: usize = 4;
pub const VQUIT: usize = 5;
pub const VREPRINT: usize = 6;
pub const VSTART: usize = 7;
pub const VSTOP: usize = 8;
pub const VSUSP: usize = 9;
pub const VWERASE: usize = 10;

pub const TCSANOW: c_int = 0;
pub const TCSADRAIN: c_int = 1;
pub const TCSAFLUSH: c_int = 2;

pub const TCOOFF: c_int = 1;
pub const TCOON: c_int = 2;
pub const TCIOFF: c_int = 3;
pub const TCION: c_int = 4;

pub const NCCS: usize = 16;

#[derive(Clone, Copy, PartialEq, Eq, Debug, Default)]
#[repr(C)]
pub struct termios {
    pub c_iflag: tcflag_t,
    pub c_oflag: tcflag_t,
    pub c_cflag: tcflag_t,
    pub c_lflag: tcflag_t,
    pub c_cc: [cc_t; NCCS],
}

#[no_mangle]
unsafe extern "C" fn tcgetattr(_fd: c_int, _termios_p: *mut termios) -> c_int {
    todo!()
}

#[no_mangle]
unsafe extern "C" fn tcsetattr(
    _fd: c_int,
    _optional_actions: c_int,
    _termios_p: *const termios,
) -> c_int {
    todo!()
}

#[no_mangle]
unsafe extern "C" fn cfmakeraw(_termios_p: *mut termios) {
    todo!()
}
