# Copyright (c) 2024 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
from enum import Enum
from typing import ClassVar

from aenum import extend_enum


class AutoExtendEnum(str, Enum):
    _original_values_: ClassVar[frozenset[str]]

    def __init_subclass__(cls, **kwargs):
        super().__init_subclass__(**kwargs)
        cls._original_values_ = frozenset(m.value for m in cls)

    @classmethod
    def _missing_(cls, value):
        extend_enum(cls, value, value)
        return cls(value)

    @classmethod
    def get_unknown_values(cls) -> frozenset[str]:
        """Return values added to this enum at runtime via `_missing_`."""
        original = cls.__dict__.get('_original_values_', frozenset())
        return frozenset(m.value for m in cls) - original
