use std::time::Duration;
use crate::{BitRate, NfcState};
use crate::constants::ComplianceMode;
use crate::rf::{LmConfPA, LmConfPF};

// TODO: Implement NFC-B, NFC-F, NFC-V, ST25TB, AP2P
mod nfca;
mod iso_dep;

/// NFCID1
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct NfcId1 {
    /// NFCID1
    pub nfcid1: [u8; 10],
    /// Length of NFCID1
    pub len: u8,
}



// TODO: Have th enum contain the device
#[derive(Debug, Copy, Clone, PartialEq)]
pub(crate) enum DeviceType {
    ListenTypeNfcA =  0,   /* NFC-A Listener device type  */
    ListenTypeNfcB =  1,   /* NFC-B Listener device type  */
    ListenTypeNfcF =  2,   /* NFC-F Listener device type  */
    ListenTypeNfcV =  3,   /* NFC-V Listener device type  */
    ListenTypeST25TB =  4,   /* ST25TB Listener device type */
    ListenTypeAp2p =  5,   /* AP2P Listener device type   */
    PollTypeNfcA =  10,  /* NFC-A Poller device type    */
    PollTypeNfcB =  11,  /* NFC-B Poller device type    */
    PollTypeNfcF =  12,  /* NFC-F Poller device type    */
    PollTypeNfcV =  13,  /* NFC-V Poller device type    */
    PollTypeAp2p =  15   /* AP2P Poller device type     */
}

#[derive(Debug, Copy, Clone)]
pub(crate) enum RfInterface {
    Rf = 0,   /* RF Frame interface */
    IsoDep = 1,   /* ISO-DEP interface  */
    NfcDep = 2,   /* NFC-DEP interface  */
}

/// Device struct containing all its details
#[derive(Debug, Clone)]
pub(crate) struct Device {
    /// Device type
    pub device_type: DeviceType, // TODO: enum should wrap the device
    /// NFCID1
    pub nfcid1: NfcId1,
    /// RF interface
    pub rf_interface: RfInterface,
    // Protocol
    // TODO: add enum for proto and implement isodep and nfcdep
}

// TODO: Implement Wakeup Config

/// Discovery Parameters

#[derive(Debug, Copy, Clone)]
pub(crate) struct DiscoveryParams {
    /// Compliance mode to be used
    compliance_mode: ComplianceMode,
    /// Number of Technologies to search for
    techs_2_find: u16,
    /// Duration of whole Poll + Listen Cycle
    total_duration: Duration,
    /// Max Number of devices
    dev_limit: u8,
    /// Bit rate to poll for NFC-F
    poll_br: BitRate,
    /// NFCID3 to be used on the ATR_REQ/ATR_RES
    nfcid3: NfcId1,
    /// General bytes to be used on the ATR-REQ
    gb: [u8; 48],
    /// Bit rate to poll for AP2P
    ap2p_br: BitRate,

    /// Configuration for Passive Listen mode NFC-A
    lm_conf_pa: LmConfPA,
    /// Configuration for Passive Listen mode NFC-F
    lm_conf_pf: LmConfPF,

    /// Callback to notify upper layer
    notify_cb: fn(NfcState),

    /// Eanble Wake-Up mode before polling
    wakeup_enable: bool,
    /// Wake-Up mode default configuration
    wakeup_cfg_default: bool,
    /// Wake-Up mode configuration
    wakeup_cfg: Wake
}
