use crate::protocol::client::ClientProtocol;
use dope_core::addr::SockAddr;
use dope_core::driver::{IoRequest, PoolDriver};

use super::super::slot::INGRESS_BUF_CAP;
use crate::session::ClientSessionGeneric;

pub(crate) const CLIENT_IOV_CAP: usize = 32;

pub(crate) const CLIENT_BYTES_CAP: usize = 256 * 1024;

pub(crate) enum ClientSlotPhase<B: PoolDriver> {
    Idle,
    Connecting {
        fixed_idx: u32,
        raw_fd: i32,
        request: IoRequest<B, SockAddr>,
    },
    Active,
}

impl<B: PoolDriver> Default for ClientSlotPhase<B> {
    #[inline(always)]
    fn default() -> Self {
        Self::Idle
    }
}

pub struct ClientSlotState<P: ClientProtocol, B: PoolDriver> {
    pub(crate) session: ClientSessionGeneric<P, INGRESS_BUF_CAP, CLIENT_IOV_CAP>,
    pub(crate) phase: ClientSlotPhase<B>,
    pub(crate) upstream_tag: u32,
}

impl<P: ClientProtocol, B: PoolDriver> Default for ClientSlotState<P, B> {
    fn default() -> Self {
        Self {
            session: ClientSessionGeneric::default(),
            phase: ClientSlotPhase::Idle,
            upstream_tag: 0,
        }
    }
}
