# Path: data_cube_utilities/dc_utilities.py
# def get_range(platform, collection, level):
#     """
#     Obtain the "valid" value range for a given combination of platform, 
#     collection, level, and data variable (does vary by data variable for some products).
# 
#     Parameters
#     ----------
#     platform: str
#         A string denoting the platform to be used. Can be 
#         "LANDSAT_5", "LANDSAT_7", or "LANDSAT_8".
#     collection: string
#         The Landsat collection of the data. 
#         Can be any of ['c1', 'c2'] for Collection 1 or 2, respectively.
#     level: string
#         The processing level of the Landsat data. 
#         Currently only 'l2' (Level 2) is supported.
# 
#     Returns
#     -------
#     range: dict or list or None
#         A dict of 2-tuples (lists) denoting the range for each data variable with a recorded range.
#         `None` otherwise.
#     """
#     range_dict = None
#     if (platform, collection, level) in \
#         [('LANDSAT_5', 'c1', 'l2'), ('LANDSAT_7', 'c1', 'l2'),
#             ('LANDSAT_8', 'c1', 'l2')]:
#         range_dict = {'red': [0, 10000], 'green': [0, 10000], 'blue': [0, 10000],
#                       'nir': [0, 10000], 'swir1': [0, 10000], 'swir2': [0, 10000]}
#     elif (platform, collection, level) in \
#         [('LANDSAT_5', 'c2', 'l2'), ('LANDSAT_7', 'c2', 'l2'),
#             ('LANDSAT_8', 'c2', 'l2')]:
#         range_dict = {'red': [1, 65455], 'green': [1, 65455], 'blue': [1, 65455],
#                       'nir': [1, 65455], 'swir1': [1, 65455], 'swir2': [1, 65455]}
#     return range_dict


import warnings
import numpy as np
import xarray as xr
from .dc_utilities import get_range

def landsat_clean_mask_invalid(dataset, platform, collection, level):
    """
    Masks out invalid data according to the LANDSAT
    surface reflectance specifications. See this document:
    https://landsat.usgs.gov/sites/default/files/documents/ledaps_product_guide.pdf pages 19-20.

    Parameters
    ----------
    dataset: xarray.Dataset
        An `xarray.Dataset` containing bands such as 'red', 'green', or 'blue'.
    platform: str
        A string denoting the platform to be used. Can be
        "LANDSAT_5", "LANDSAT_7", or "LANDSAT_8".
    collection: string
        The Landsat collection of the data.
        Can be any of ['c1', 'c2'] for Collection 1 or 2, respectively.
    level: string
        The processing level of the Landsat data.
        Currently only 'l2' (Level 2) is supported.

    Returns
    -------
    valid_mask: xarray.DataArray
        An `xarray.DataArray` with the same number and order of coordinates as in `dataset`.
        The `True` values specify what pixels are valid.
    """
    valid_mask = None
    data_arr_names = [arr_name for arr_name in list(dataset.data_vars)
                      if arr_name not in ['pixel_qa', 'radsat_qa', 'cloud_qa']]

# Path: data_cube_utilities/dc_utilities.py
# def get_range(platform, collection, level):
#     """
#     Obtain the "valid" value range for a given combination of platform, 
#     collection, level, and data variable (does vary by data variable for some products).
# 
#     Parameters
#     ----------
#     platform: str
#         A string denoting the platform to be used. Can be 
#         "LANDSAT_5", "LANDSAT_7", or "LANDSAT_8".
#     collection: string
#         The Landsat collection of the data. 
#         Can be any of ['c1', 'c2'] for Collection 1 or 2, respectively.
#     level: string
#         The processing level of the Landsat data. 
#         Currently only 'l2' (Level 2) is supported.
# 
#     Returns
#     -------
#     range: dict or list or None
#         A dict of 2-tuples (lists) denoting the range for each data variable with a recorded range.
#         `None` otherwise.
#     """
#     range_dict = None
#     if (platform, collection, level) in \
#         [('LANDSAT_5', 'c1', 'l2'), ('LANDSAT_7', 'c1', 'l2'),
#             ('LANDSAT_8', 'c1', 'l2')]:
#         range_dict = {'red': [0, 10000], 'green': [0, 10000], 'blue': [0, 10000],
#                       'nir': [0, 10000], 'swir1': [0, 10000], 'swir2': [0, 10000]}
#     elif (platform, collection, level) in \
#         [('LANDSAT_5', 'c2', 'l2'), ('LANDSAT_7', 'c2', 'l2'),
#             ('LANDSAT_8', 'c2', 'l2')]:
#         range_dict = {'red': [1, 65455], 'green': [1, 65455], 'blue': [1, 65455],
#                       'nir': [1, 65455], 'swir1': [1, 65455], 'swir2': [1, 65455]}
#     return range_dict


# Path: data_cube_utilities/clean_mask.py
import warnings
import numpy as np
import xarray as xr
from .dc_utilities import get_range


def landsat_clean_mask_invalid(dataset, platform, collection, level):
    """
    Masks out invalid data according to the LANDSAT
    surface reflectance specifications. See this document:
    https://landsat.usgs.gov/sites/default/files/documents/ledaps_product_guide.pdf pages 19-20.

    Parameters
    ----------
    dataset: xarray.Dataset
        An `xarray.Dataset` containing bands such as 'red', 'green', or 'blue'.
    platform: str
        A string denoting the platform to be used. Can be
        "LANDSAT_5", "LANDSAT_7", or "LANDSAT_8".
    collection: string
        The Landsat collection of the data.
        Can be any of ['c1', 'c2'] for Collection 1 or 2, respectively.
    level: string
        The processing level of the Landsat data.
        Currently only 'l2' (Level 2) is supported.

    Returns
    -------
    valid_mask: xarray.DataArray
        An `xarray.DataArray` with the same number and order of coordinates as in `dataset`.
        The `True` values specify what pixels are valid.
    """
    valid_mask = None
    data_arr_names = [arr_name for arr_name in list(dataset.data_vars)
                      if arr_name not in ['pixel_qa', 'radsat_qa', 'cloud_qa']]

    rng = get_range(platform, collection, level)