# Copyright (c) 2023 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
from datetime import datetime
from enum import Enum
from toolz import keyfilter
from typing import NamedTuple
from voluptuous import Coerce, Maybe, Required, Schema, REMOVE_EXTRA

from czc.type_util import deserializable, isoparse, serializable


class CloudProvider(str, Enum):
    datadog = 'datadog'


@deserializable(schema=Schema({
    Required('connection_id'): str,
    Required('organization_id'): str,
    Required('name'): str,
    Required('cloud_provider'): Coerce(CloudProvider),
    Required('created'): Maybe(isoparse),
    Required('last_updated'): Maybe(isoparse),
    'provider_config': dict,
    'is_enabled': bool,
    'is_deleted': bool,
    'capabilities': dict
}, extra=REMOVE_EXTRA))
class AnyCostConnectionInfo(NamedTuple):
    connection_id: str
    organization_id: str
    name: str
    cloud_provider: CloudProvider
    created: datetime
    last_updated: datetime
    provider_config: dict = {}
    is_enabled: bool = True
    is_deleted: bool = False
    capabilities: dict = {}

    @staticmethod
    def _is_public_field(field_name: str) -> bool:
        return field_name not in {'is_deleted'}

    def to_public(self) -> dict:
        return keyfilter(self._is_public_field, serializable(self))
