# -*- coding: utf-8 -*-
"""
Satellite configuration registry.

Defines supported satellite collections, band compositions,
cloud masking parameters, and visualization settings.

Author: Loc Vu Trung / Slow Forest
License: GPL-3.0
"""

# ---------------------------------------------------------------------------
# Satellite Definitions
# ---------------------------------------------------------------------------
SATELLITES = {
    "S2_SR": {
        "name": "Sentinel-2 L2A (10 m)",
        "collection": "COPERNICUS/S2_SR_HARMONIZED",
        "cloud_field": "CLOUDY_PIXEL_PERCENTAGE",
        "cloud_mask_band": "SCL",
        "cloud_mask_values": [3, 7, 8, 9, 10],
        "default_scale": 10,
        "date_start": "2017-03-28",
        "bands": {
            "True Color (B4-B3-B2)": {
                "ee_bands": ["B4", "B3", "B2"],
                "min": 0, "max": 3000,
                "description": "Natural color composite",
            },
            "False Color NIR (B8-B4-B3)": {
                "ee_bands": ["B8", "B4", "B3"],
                "min": 0, "max": 5000,
                "description": "Vegetation appears red",
            },
            "SWIR (B12-B8A-B4)": {
                "ee_bands": ["B12", "B8A", "B4"],
                "min": 0, "max": 5000,
                "description": "Urban, soil, burn scars",
            },
            "Agriculture (B11-B8-B2)": {
                "ee_bands": ["B11", "B8", "B2"],
                "min": 0, "max": 5000,
                "description": "Crop health & moisture",
            },
            "NDVI": {
                "index": True,
                "formula_bands": ["B8", "B4"],
                "palette": ["#d73027", "#fc8d59", "#fee08b",
                            "#d9ef8b", "#91cf60", "#1a9850"],
                "min": -0.2, "max": 0.9,
                "description": "Normalized Difference Vegetation Index",
            },
            "EVI": {
                "index": True,
                "formula_bands": ["B8", "B4", "B2"],
                "palette": ["#d73027", "#fc8d59", "#fee08b",
                            "#d9ef8b", "#91cf60", "#1a9850"],
                "min": -0.2, "max": 0.9,
                "description": "Enhanced Vegetation Index",
            },
            "NDWI": {
                "index": True,
                "formula_bands": ["B3", "B8"],
                "palette": ["#ffffcc", "#a1dab4", "#41b6c4",
                            "#2c7fb8", "#253494"],
                "min": -0.5, "max": 0.5,
                "description": "Normalized Difference Water Index",
            },
            "All Bands (B2-B12)": {
                "ee_bands": ["B2", "B3", "B4", "B5", "B6", "B7",
                             "B8", "B8A", "B11", "B12"],
                "min": 0, "max": 3000,
                "description": "All 10 spectral bands",
            },
        },
        "resolutions": [10, 20, 60],
    },

    "L8_SR": {
        "name": "Landsat 8 OLI (30 m)",
        "collection": "LANDSAT/LC08/C02/T1_L2",
        "cloud_field": "CLOUD_COVER",
        "cloud_mask_band": "QA_PIXEL",
        "cloud_mask_bits": [3, 4],  # cloud, cloud shadow
        "default_scale": 30,
        "date_start": "2013-04-01",
        "bands": {
            "True Color (B4-B3-B2)": {
                "ee_bands": ["SR_B4", "SR_B3", "SR_B2"],
                "min": 7000, "max": 20000,
                "description": "Natural color composite",
            },
            "False Color NIR (B5-B4-B3)": {
                "ee_bands": ["SR_B5", "SR_B4", "SR_B3"],
                "min": 7000, "max": 30000,
                "description": "Vegetation appears red",
            },
            "SWIR (B7-B5-B4)": {
                "ee_bands": ["SR_B7", "SR_B5", "SR_B4"],
                "min": 7000, "max": 30000,
                "description": "Urban, soil, burn scars",
            },
            "NDVI": {
                "index": True,
                "formula_bands": ["SR_B5", "SR_B4"],
                "palette": ["#d73027", "#fc8d59", "#fee08b",
                            "#d9ef8b", "#91cf60", "#1a9850"],
                "min": -0.2, "max": 0.9,
                "description": "Normalized Difference Vegetation Index",
            },
            "All Bands": {
                "ee_bands": ["SR_B1", "SR_B2", "SR_B3", "SR_B4",
                             "SR_B5", "SR_B6", "SR_B7"],
                "min": 7000, "max": 20000,
                "description": "All 7 surface reflectance bands",
            },
        },
        "resolutions": [30],
    },

    "L9_SR": {
        "name": "Landsat 9 OLI-2 (30 m)",
        "collection": "LANDSAT/LC09/C02/T1_L2",
        "cloud_field": "CLOUD_COVER",
        "cloud_mask_band": "QA_PIXEL",
        "cloud_mask_bits": [3, 4],
        "default_scale": 30,
        "date_start": "2021-10-31",
        "bands": {
            "True Color (B4-B3-B2)": {
                "ee_bands": ["SR_B4", "SR_B3", "SR_B2"],
                "min": 7000, "max": 20000,
                "description": "Natural color composite",
            },
            "False Color NIR (B5-B4-B3)": {
                "ee_bands": ["SR_B5", "SR_B4", "SR_B3"],
                "min": 7000, "max": 30000,
                "description": "Vegetation appears red",
            },
            "NDVI": {
                "index": True,
                "formula_bands": ["SR_B5", "SR_B4"],
                "palette": ["#d73027", "#fc8d59", "#fee08b",
                            "#d9ef8b", "#91cf60", "#1a9850"],
                "min": -0.2, "max": 0.9,
                "description": "Normalized Difference Vegetation Index",
            },
            "All Bands": {
                "ee_bands": ["SR_B1", "SR_B2", "SR_B3", "SR_B4",
                             "SR_B5", "SR_B6", "SR_B7"],
                "min": 7000, "max": 20000,
                "description": "All 7 surface reflectance bands",
            },
        },
        "resolutions": [30],
    },

    "S1_GRD": {
        "name": "Sentinel-1 SAR (10 m)",
        "collection": "COPERNICUS/S1_GRD",
        "cloud_field": None,  # SAR not affected by cloud
        "default_scale": 10,
        "date_start": "2014-10-03",
        "bands": {
            "VV Polarization": {
                "ee_bands": ["VV"],
                "min": -25, "max": 0,
                "description": "Co-polarization (vertical)",
            },
            "VH Polarization": {
                "ee_bands": ["VH"],
                "min": -30, "max": -5,
                "description": "Cross-polarization",
            },
            "VV + VH Composite": {
                "ee_bands": ["VV", "VH"],
                "min": -25, "max": 0,
                "description": "Dual-pol composite",
            },
        },
        "resolutions": [10],
        "extra_filter": {
            "instrumentMode": "IW",
            "resolution_meters": 10,
        },
    },

    "MODIS_NDVI": {
        "name": "MODIS Terra NDVI (250 m)",
        "collection": "MODIS/061/MOD13Q1",
        "cloud_field": None,
        "default_scale": 250,
        "date_start": "2000-02-18",
        "bands": {
            "NDVI": {
                "ee_bands": ["NDVI"],
                "min": 0, "max": 9000,
                "scale_factor": 0.0001,
                "palette": ["#d73027", "#fc8d59", "#fee08b",
                            "#d9ef8b", "#91cf60", "#1a9850"],
                "description": "16-day NDVI composite",
            },
            "EVI": {
                "ee_bands": ["EVI"],
                "min": 0, "max": 9000,
                "scale_factor": 0.0001,
                "palette": ["#d73027", "#fc8d59", "#fee08b",
                            "#d9ef8b", "#91cf60", "#1a9850"],
                "description": "16-day EVI composite",
            },
        },
        "resolutions": [250],
    },
}

# ---------------------------------------------------------------------------
# Composite Methods
# ---------------------------------------------------------------------------
COMPOSITES = [
    ("median", "Median"),
    ("mean", "Mean"),
    ("min", "Min (darkest)"),
    ("max", "Max (brightest)"),
    ("mosaic", "Mosaic (latest on top)"),
]
