# Path: irisett/log.py
# def configure_logging(logtype: str, logfilename: Optional[str]=None, debug_logging: bool=False,
#                       rotate_length: int=1000000, max_rotated_files: int=250) -> None:
# def msg(logmsg: str, section: Optional[str]=None) -> None:
# def debug(logmsg: str, section: Optional[str]=None) -> None:
#     def log_msg(self, logmsg: str) -> None:
#     def log_debug(self, logmsg: str) -> None:
# class LoggingMixin:
# 
# Path: irisett/notify/email.py
# async def send_email(loop: asyncio.AbstractEventLoop, mail_from: str, mail_to: Union[Iterable, str],
#                      subject: str, body: str, server: str='localhost') -> None:
# async def send_alert_notification(
#         loop: asyncio.AbstractEventLoop, settings: Dict[str, Any],
#         recipients: Iterable[str], tmpl_args: Dict[str, Any]) -> None:
# def parse_settings(config: Any) -> Optional[Dict[str, Any]]:
# 
# Path: irisett/notify/http.py
# async def send_http_notification(url: str, in_data: Any):
# async def send_alert_notification(settings: Dict[str, Any], email_recipients: Iterable[str],
#                                   sms_recipients: Iterable[str], tmpl_args: Dict[str, Any]):
# def parse_settings(config: Any) -> Optional[Dict[str, Any]]:
# 
# Path: irisett/notify/sms.py
# def parse_settings(config: Any) -> Optional[Dict[str, Any]]:
# async def send_alert_notification(settings: Dict[str, Any], recipients: Iterable[str], tmpl_args: Dict[str, Any]):
# 
# Path: irisett/notify/clicksend.py
# CLICKSEND_URL = 'https://rest.clicksend.com/v3/sms/send'
# async def send_sms(recipients: Iterable[str], msg: str, username: str, api_key: str, sender: str):
# def parse_settings(config: Any) -> Optional[Dict[str, Any]]:
# 
# Path: irisett/notify/slack.py
# async def send_slack_notification(url: str, attachments: List[Dict]):
# async def send_alert_notification(settings: Dict, tmpl_args: Dict):
# def parse_settings(config: Any) -> Optional[Dict[str, Any]]:


from typing import Dict, Iterable, Any, List
from irisett import (
    log,
)
from irisett.notify import (
    email,
    http,
    sms,
    clicksend,
    slack,
)
import asyncio



# noinspection PyMethodMayBeStatic
class NotificationManager:
    def __init__(self, config: Any, *, loop: asyncio.AbstractEventLoop=None) -> None:
        self.loop = loop or asyncio.get_event_loop()
        if not config:
            log.msg('Missing config section, no alert notification will be sent', 'NOTIFICATIONS')
            self.http_settings = None
            self.email_settings = None
            self.sms_settings = None
            self.slack_settings = None
        else:
            self.http_settings = http.parse_settings(config)
            self.email_settings = email.parse_settings(config)
            self.sms_settings = sms.parse_settings(config)
            self.slack_settings = slack.parse_settings(config)

    async def send_notification(self, recipient_dict: Dict[str, Any], tmpl_args: Dict[str, Any]) -> bool:
        email_recipients = list(recipient_dict['email'])
        sms_recipients = list(recipient_dict['phone'])
        if email_recipients and self.email_settings:
            await email.send_alert_notification(self.loop, self.email_settings, email_recipients, tmpl_args)
        if sms_recipients and self.sms_settings:
            await sms.send_alert_notification(self.sms_settings, sms_recipients, tmpl_args)
        if self.http_settings:
            await http.send_alert_notification(self.http_settings, email_recipients, sms_recipients, tmpl_args)
        if self.slack_settings:

# Path: irisett/log.py
# def configure_logging(logtype: str, logfilename: Optional[str]=None, debug_logging: bool=False,
#                       rotate_length: int=1000000, max_rotated_files: int=250) -> None:
# def msg(logmsg: str, section: Optional[str]=None) -> None:
# def debug(logmsg: str, section: Optional[str]=None) -> None:
#     def log_msg(self, logmsg: str) -> None:
#     def log_debug(self, logmsg: str) -> None:
# class LoggingMixin:
# 
# Path: irisett/notify/email.py
# async def send_email(loop: asyncio.AbstractEventLoop, mail_from: str, mail_to: Union[Iterable, str],
#                      subject: str, body: str, server: str='localhost') -> None:
# async def send_alert_notification(
#         loop: asyncio.AbstractEventLoop, settings: Dict[str, Any],
#         recipients: Iterable[str], tmpl_args: Dict[str, Any]) -> None:
# def parse_settings(config: Any) -> Optional[Dict[str, Any]]:
# 
# Path: irisett/notify/http.py
# async def send_http_notification(url: str, in_data: Any):
# async def send_alert_notification(settings: Dict[str, Any], email_recipients: Iterable[str],
#                                   sms_recipients: Iterable[str], tmpl_args: Dict[str, Any]):
# def parse_settings(config: Any) -> Optional[Dict[str, Any]]:
# 
# Path: irisett/notify/sms.py
# def parse_settings(config: Any) -> Optional[Dict[str, Any]]:
# async def send_alert_notification(settings: Dict[str, Any], recipients: Iterable[str], tmpl_args: Dict[str, Any]):
# 
# Path: irisett/notify/clicksend.py
# CLICKSEND_URL = 'https://rest.clicksend.com/v3/sms/send'
# async def send_sms(recipients: Iterable[str], msg: str, username: str, api_key: str, sender: str):
# def parse_settings(config: Any) -> Optional[Dict[str, Any]]:
# 
# Path: irisett/notify/slack.py
# async def send_slack_notification(url: str, attachments: List[Dict]):
# async def send_alert_notification(settings: Dict, tmpl_args: Dict):
# def parse_settings(config: Any) -> Optional[Dict[str, Any]]:


# Path: irisett/notify/manager.py
from typing import Dict, Iterable, Any, List
from irisett import (
    log,
)
from irisett.notify import (
    email,
    http,
    sms,
    clicksend,
    slack,
)
import asyncio




# noinspection PyMethodMayBeStatic
class NotificationManager:
    def __init__(self, config: Any, *, loop: asyncio.AbstractEventLoop=None) -> None:
        self.loop = loop or asyncio.get_event_loop()
        if not config:
            log.msg('Missing config section, no alert notification will be sent', 'NOTIFICATIONS')
            self.http_settings = None
            self.email_settings = None
            self.sms_settings = None
            self.slack_settings = None
        else:
            self.http_settings = http.parse_settings(config)
            self.email_settings = email.parse_settings(config)
            self.sms_settings = sms.parse_settings(config)
            self.slack_settings = slack.parse_settings(config)

    async def send_notification(self, recipient_dict: Dict[str, Any], tmpl_args: Dict[str, Any]) -> bool:
        email_recipients = list(recipient_dict['email'])
        sms_recipients = list(recipient_dict['phone'])
        if email_recipients and self.email_settings:
            await email.send_alert_notification(self.loop, self.email_settings, email_recipients, tmpl_args)
        if sms_recipients and self.sms_settings:
            await sms.send_alert_notification(self.sms_settings, sms_recipients, tmpl_args)
        if self.http_settings:
            await http.send_alert_notification(self.http_settings, email_recipients, sms_recipients, tmpl_args)
        if self.slack_settings:

            await slack.send_alert_notification(self.slack_settings, tmpl_args)