/*-
 * 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 smol::lock::{Mutex, MutexGuard};

use crate::{a_sync::syslog_async_internal::{AsyncMutex, AsyncMutexGuard, AsyncSyslogInternal, AsyncSyslogInternalIO}, formatters::SyslogFormatter, AsyncSyslogDestination};


pub type DefaultAsyncMutex<F, D, IO> = Mutex<AsyncSyslogInternal<F, D, IO>>;

impl<F: SyslogFormatter + Send, D: AsyncSyslogDestination, IO: AsyncSyslogInternalIO> AsyncMutex<F, D, AsyncSyslogInternal<F, D, IO>> 
for Mutex<AsyncSyslogInternal<F, D, IO>>
{
    type MutxGuard<'mux> = MutexGuard<'mux, AsyncSyslogInternal<F, D, IO>>;

    fn a_new(v: AsyncSyslogInternal<F, D, IO>) -> Self 
    {
        return Mutex::new(v);
    }
    
    fn a_lock<'mux>(&'mux self) -> impl Future<Output = Self::MutxGuard<'mux>> 
    {
        return self.lock();
    }
}

impl<'mux, F: SyslogFormatter + Send, D: AsyncSyslogDestination, IO: AsyncSyslogInternalIO> AsyncMutexGuard<'mux, F, D, AsyncSyslogInternal<F, D, IO>>
for MutexGuard<'mux, AsyncSyslogInternal<F, D, IO>>
{
    fn guard(&self) -> &AsyncSyslogInternal<F, D, IO>
    {
        return self;
    }

    fn guard_mut(&mut self) -> &mut AsyncSyslogInternal<F, D, IO>
    {
        return self;
    }
}
