# SPDX-FileCopyrightText: © 2025 DSLab - Fondazione Bruno Kessler
#
# SPDX-License-Identifier: Apache-2.0

from __future__ import annotations

from digitalhub.entities._base.versioned.builder import VersionedBuilder
from digitalhub.entities._commons.enums import EntityKinds, EntityTypes
from digitalhub.entities.extension._base.entity import Extension
from digitalhub.entities.extension._base.spec import ExtensionSpec, ExtensionValidator
from digitalhub.entities.extension._base.status import ExtensionStatus


class ExtensionExtensionBuilder(VersionedBuilder):
    """
    ExtensionExtensionBuilder builder.
    """

    ENTITY_TYPE = EntityTypes.EXTENSION.value
    ENTITY_CLASS = Extension
    ENTITY_SPEC_CLASS = ExtensionSpec
    ENTITY_SPEC_VALIDATOR = ExtensionValidator
    ENTITY_STATUS_CLASS = ExtensionStatus
    ENTITY_KIND = EntityKinds.EXTENSION_EXTENSION.value

    def build(
        self,
        kind: str,
        project: str,
        name: str,
        uuid: str | None = None,
        description: str | None = None,
        labels: list[str] | None = None,
        **kwargs,
    ) -> Extension:
        """
        Create a new object.

        Parameters
        ----------
        project : str
            Project name.
        name : str
            Object name.
        kind : str
            Kind the object.
        uuid : str
            ID of the object.
        description : str
            Description of the object (human readable).
        labels : list[str]
            List of labels.
        **kwargs : dict
            Spec keyword arguments.

        Returns
        -------
        Extension
            Object instance.
        """
        name = self.build_name(name)
        uuid = self.build_uuid(uuid)
        metadata = self.build_metadata(
            project=project,
            name=name,
            description=description,
            labels=labels,
        )
        spec = self.build_spec(**kwargs)
        status = self.build_status()
        return self.build_entity(
            project=project,
            name=name,
            uuid=uuid,
            kind=kind,
            metadata=metadata,
            spec=spec,
            status=status,
        )
