# 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 collections.abc import Mapping

from .common import iapi

GLOBAL_VIEW_ID = 'DEFAULT'
FEATURE_VIEWS_IAPI = {
    'namespace': lambda _: os.environ.get('VIEWS_NAMESPACE') or os.environ['NAMESPACE'],
    'feature': 'views',
}


@iapi('get-org-views')
def get_all_views(*, cz_organization_id: str) -> Mapping:
    """
    Get all views for an organization.

    Args:
        cz_organization_id: The ID of the organization.

    Returns:
        Mapping containing the views for the organization.
        Sample response: {'data': { 'views': [...]}}
    """


@iapi('get-view')
def get_view(*, cz_organization_id: str, view_id: str) -> Mapping:
    """
    Get a view for an organization.

    Args:
        cz_organization_id: The ID of the organization.
        view_id: The ID of the view.

    Returns:
        Mapping containing the view for the organization.
        Sample response:
        { 'view': {
                'id': 'string (UUID or "DEFAULT")',
                'name': 'string',
                'principal_dimension': 'string',
                'filter': {},  # dict of {dimension: [values]}
                'connections': {},  # Only present if non-empty
                'anomalies': {},  # Anomaly settings if configured
                'last_updated': 'string',
                'last_edited': 'datetime or None'
            }
        }
    """
