#  NOTICE: Confidential and Proprietary Information of OPT/NET B.V.
#
#  This file contains confidential and proprietary information of OPT/NET B.V. and is intended solely for use by authorized personnel.
#  Unauthorized disclosure, reproduction, distribution, or use of this file, in whole or in part, without the express written permission of OPT/NET B.V., is strictly prohibited. This includes, but is not limited to, sharing this file or its contents with third parties or uploading it to public repositories or forums.
#
#  Developers are reminded to exercise caution and maintain the confidentiality of proprietary information when working with this file.
#  Any unauthorized sharing or distribution of this file may result in disciplinary action, including termination of employment, and may expose OPT/NET B.V. to legal liabilities.
#
#  For questions or clarifications regarding the handling of confidential information, developers should contact the Information Security Officer or the appropriate authority within OPT/NET B.V. before sharing or disclosing this file to third parties.
#
#  By using this file, developers acknowledge and agree to abide by the confidentiality and proprietary rights policies of OPT/NET B.V.
#
#  Copyright © 2026 OPT/NET B.V. All rights reserved.

from __future__ import annotations

from typing import TYPE_CHECKING, Dict, List

from ocli.finders.finder_planetarycomputer_landsat_8 import (
    FinderPlanetaryComputerLANDSAT8,
)
from ocli.helpers.update_visible_metadata import update_visible_metadata
from .config import RECIPE_DEFAULTS, TASK_DEFAULTS
from ..template import TemplateCompositeSingle

if TYPE_CHECKING:
    from ocli.classes.task import Task


class Template(TemplateCompositeSingle):
    """The composite_single.landsat_8 template class.

    Uses Microsoft Planetary Computer STAC API via `FinderPlanetaryComputerLANDSAT8`
    (attached through `TaskTemplate.get_finder`) to discover and download free
    Landsat-8 Collection 2 Level-2 products.
    """

    __version__ = 2.0
    template_recipe_conf = {**TemplateCompositeSingle.template_recipe_conf, **RECIPE_DEFAULTS}
    template_task_conf = {**TemplateCompositeSingle.template_task_conf, **TASK_DEFAULTS}

    @classmethod
    def get_finder(cls, task: Task) -> FinderPlanetaryComputerLANDSAT8:
        """Return the Planetary Computer Landsat-8 Level-2 Finder for this AIKP."""
        return FinderPlanetaryComputerLANDSAT8(
            eodata_home=task.get_eodata_home_path(),
            cache_dir=task.get_project_cache_path(),
        )

    @classmethod
    def update_recipe(cls, task: Task, recipe: Dict, roi: Dict = None) -> List:
        """Update recipe entries specific to composite_single.landsat_8."""
        errors = super().update_recipe(task, recipe, roi)
        update_visible_metadata(
            recipe,
            {
                "Instrument": "Landsat-8 (Collection 2 Level-2)",
                "Master Info": task.config["master"],
                "template": f'{task.config["template"]}:{task.config["template_version"]}',
                "project": task.config["project"],
            },
        )
        return errors
