/*-
 * syslog-rs - a syslog client translated from libc to rust
 * 
 * Copyright 2025 Aleksandr Morozov
 * 
 * The syslog-rs crate can be redistributed and/or modified
 * under the terms of either of the following licenses:
 *
 *   1. the Mozilla Public License Version 2.0 (the “MPL”) OR
 *
 *   2. The MIT License (MIT)
 *                     
 *   3. EUROPEAN UNION PUBLIC LICENCE v. 1.2 EUPL © the European Union 2007, 2016
 */


use std::fmt;


/// An enum of types of the current syslog tap instance.
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum TapType
{
    /// Not defined
    None, 

    /// Unprivileged socket used
    UnPriv,

    /// Privileged socket used
    Priv,

    /// A compatibility socket used
    OldLog,

    /// Custom unix datagram
    CustomLog,

    /// Windows only event log
    WindowsEventLog,

    /// Writing to file directly
    LocalFile,

    /// Network UDP
    NetUdp,

    /// Network TCP
    NetTcp,

    /// Network TLS over TCP
    NetTls,
}

impl fmt::Display for TapType
{
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result 
    {
        match self
        {
            Self::None => 
                write!(f, "NO TYPE"),
            Self::UnPriv => 
                write!(f, "UNPRIV"),
            Self::Priv => 
                write!(f, "PRIV"),
            Self::OldLog =>
                write!(f, "OLD LOG"),
            Self::CustomLog => 
                write!(f, "CUSTOM LOG"),
            Self::WindowsEventLog =>
                write!(f, "WINDOWS EVENT LOG"),
            Self::LocalFile =>
                write!(f, "LOCAL FILE"),
            Self::NetUdp => 
                write!(f, "NET UDP"),
            Self::NetTcp => 
                write!(f, "NET TCP"),
            Self::NetTls => 
                write!(f, "NET TLS TCP")
        }
    }
}

impl TapType
{
    pub(crate) 
    fn is_priv(&self) -> bool
    {
        return *self == Self::Priv;
    }

    #[allow(dead_code)]
    pub(crate) 
    fn is_network(&self) -> bool
    {
        return *self == Self::NetTcp || *self == Self::NetUdp || *self == Self::NetTls;
    }

    #[allow(dead_code)]
    pub(crate)
    fn is_file(&self) -> bool
    {
        return *self == Self::LocalFile;
    }

}