# -*- coding: utf-8 -*-
# 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
from dataclasses import dataclass
from datetime import datetime
from typing import Dict, List, NamedTuple

from billing_iapi.types import CostType
from czc.type_util import deserializable
from data_access_controls_iapi.api.web.types import AuthorizationContext
from dimensions_iapi.models import Fqdid

from .common import invokes_billing_api
from .partition_type import PartitionType
from .types import GranularityType


class DateRange(NamedTuple):
    start: datetime
    end: datetime


class RelevantPartitionCriteria(NamedTuple):
    data_points: int
    max_hourly_cost: float


@deserializable()
@dataclass(frozen=True)
class AvailableDimension:
    fqdid: Fqdid
    aliases: List[str]
    display_name: str
    hidden: bool


@deserializable()
@dataclass(frozen=True)
class AvailableDimensions:
    dimensions: List[AvailableDimension]


@invokes_billing_api(api='get-billing-data')
def get_billing_data(*, organization_id: str, date_range: DateRange,
                     granularity: GranularityType = GranularityType.daily, partitions: List[PartitionType] = None,
                     filters: Dict[PartitionType, List[str]] = None, cost_type: CostType = CostType.real_cost, authorization_context: AuthorizationContext = None):
    pass


@invokes_billing_api(api='get-data-projection')
def get_data_projection(*, organization_id: str,
                        date_range: DateRange,
                        dimensions: Dict[str, PartitionType],
                        granularity: GranularityType = GranularityType.daily,
                        filters: Dict[PartitionType, List[str]] = None):
    pass


@invokes_billing_api(api='get-total-cost-per-hour')
def get_total_cost_per_hour(*, organization_id: str, date_range: DateRange,
                            filters: Dict[PartitionType, List[str]] = None):
    pass


@invokes_billing_api(api='get-total-cost-per-hour-by-element')
def get_total_cost_per_hour_by_element(*, organization_id: str, date_range: DateRange,
                                       partition: PartitionType, filters: Dict[PartitionType, List[str]] = None):
    pass


@invokes_billing_api(api='get-average-daily-cost-per-partition')
def get_average_daily_cost_per_partition(*, organization_id: str,
                                         partition: PartitionType, date_range: DateRange,
                                         filters: Dict[PartitionType, List[str]] = None):
    pass


@invokes_billing_api(api='get-top-partitions')
def get_top_partitions(*, organization_id: str, partition: PartitionType, count: int,
                       date_range: DateRange, filters: Dict[PartitionType, List[str]] = None):
    pass


@invokes_billing_api(api='get-relevant-partition-sets')
def get_relevant_partition_sets(*, organization_id: str, partitions: List[PartitionType],
                                date_range: DateRange, criteria: RelevantPartitionCriteria = None,
                                filters: Dict[PartitionType, List[str]] = None):
    pass


@invokes_billing_api(api='get-member-available-partitions-v2')
def get_member_available_partitions(*, organization_id: str, include_hidden: bool = False):
    pass


@invokes_billing_api(api='get-partition-values')
def get_partition_values(*, organization_id: str, partition: PartitionType,
                         date_range: DateRange = None, granularity: GranularityType = GranularityType.daily,
                         match: str = None, limit: int = None):
    pass


@invokes_billing_api(api='get-active-telemetry-streams')
def get_active_telemetry_streams(*, organization_id: str):
    pass


@invokes_billing_api(api='get-available-dimensions')
def get_available_dimensions(*, organization_id: str, include_hidden: bool = False) -> AvailableDimensions:
    pass
