# Copyright (c) 2021 CloudZero - ALL RIGHTS RESERVED - PROPRIETARY AND CONFIDENTIAL
# Unauthorized copying of this file and/or project, via any medium is strictly prohibited.
# Direct all questions to legal@cloudzero.com

import os
from typing import Dict, List, Mapping, NamedTuple

import czc.date as date
import czc.internal_api.client as client
from czc.constants import FEATURE_NAME

FEATURE_NOTIFICATIONS_IAPI = {
    'namespace': lambda _: os.environ.get('NOTIFICATIONS_NAMESPACE') or os.environ['NAMESPACE'],
    'feature': 'notifications',
}


class NotificationMetadata(NamedTuple):
    cz_organization_id: str
    type: str
    title: str
    description: str
    severity: str = 'INFORMATION'
    cloud_account_ids: List[str] = []
    links: List[str] = []
    tags: Dict[str, str] = {}
    timestamp: float = date.get_current_timestamp()
    source: str = FEATURE_NAME


class View(NamedTuple):
    id: str = 'DEFAULT'


class EmailChannel(NamedTuple):
    addresses: List[str] = []
    include_all_organizers: bool = False


class SlackChannel(NamedTuple):
    id: str
    name: str = None


class Channels(NamedTuple):
    email: EmailChannel = None
    slack: List[SlackChannel] = None


@client.invoked(**FEATURE_NOTIFICATIONS_IAPI, api='send-to-view')
def send_to_view(metadata: NotificationMetadata, view: View, data: Mapping) -> dict:  # type: ignore
    pass


@client.invoked(**FEATURE_NOTIFICATIONS_IAPI, api='send-to-channels')
def send_to_channels(metadata: NotificationMetadata, channels: Channels, data: Mapping) -> dict:  # type: ignore
    pass


@client.invoked(**FEATURE_NOTIFICATIONS_IAPI, api='get-slack-channel')
def get_slack_channel(organization_id: str, channel_id: str) -> dict:  # type: ignore
    pass
