# coding: utf-8

"""
    Mixpeek API

    This is the Mixpeek API, providing access to various endpoints for data processing and retrieval.

    The version of the OpenAPI document: 1.3.0
    Contact: info@mixpeek.com
    Generated by OpenAPI Generator (https://openapi-generator.tech)

    Do not edit the class manually.
"""  # noqa: E501


from __future__ import annotations
import pprint
import re  # noqa: F401
import json

from pydantic import BaseModel, ConfigDict, Field, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from typing_extensions import Annotated
from mixpeek.models.alert_execution_mode import AlertExecutionMode
from mixpeek.models.alert_input_mapping import AlertInputMapping
from mixpeek.models.post_processing_phase import PostProcessingPhase
from typing import Optional, Set
from typing_extensions import Self

class AlertApplicationConfigInput(BaseModel):
    """
    Configuration for attaching an alert to a collection.  The key responsibility here is INPUT MAPPING: connecting document fields (or constants) to the retriever's expected inputs.  Note: Filtering logic (scroll_filters, min_score, etc.) belongs in the retriever, not here. The retriever owns all query semantics.  Use Cases:     - Attach safety alert to video upload collection     - Configure different field mappings for different collections     - Set execution priority for multiple alerts  Attributes:     alert_id: ID of the alert to execute     execution_mode: When this alert should execute     input_mappings: Map document fields or constants to retriever inputs     execution_phase: Which phase this alert runs in (default: ALERT)     priority: Priority within the execution phase (higher = runs first)
    """ # noqa: E501
    alert_id: StrictStr = Field(description="ID of the alert to execute")
    execution_mode: Optional[AlertExecutionMode] = Field(default=None, description="When this alert should execute")
    input_mappings: Annotated[List[AlertInputMapping], Field(min_length=1)] = Field(description="Map document fields or constants to retriever input parameters")
    execution_phase: Optional[PostProcessingPhase] = Field(default=None, description="Which phase this alert runs in. Default: ALERT (phase 3, after taxonomies and clusters)")
    priority: Optional[Annotated[int, Field(le=1000, strict=True, ge=0)]] = Field(default=0, description="Priority within the execution phase (higher = runs first)")
    additional_properties: Dict[str, Any] = {}
    __properties: ClassVar[List[str]] = ["alert_id", "execution_mode", "input_mappings", "execution_phase", "priority"]

    model_config = ConfigDict(
        populate_by_name=True,
        validate_assignment=True,
        protected_namespaces=(),
    )


    def to_str(self) -> str:
        """Returns the string representation of the model using alias"""
        return pprint.pformat(self.model_dump(by_alias=True))

    def to_json(self) -> str:
        """Returns the JSON representation of the model using alias"""
        # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
        return json.dumps(self.to_dict())

    @classmethod
    def from_json(cls, json_str: str) -> Optional[Self]:
        """Create an instance of AlertApplicationConfigInput from a JSON string"""
        return cls.from_dict(json.loads(json_str))

    def to_dict(self) -> Dict[str, Any]:
        """Return the dictionary representation of the model using alias.

        This has the following differences from calling pydantic's
        `self.model_dump(by_alias=True)`:

        * `None` is only added to the output dict for nullable fields that
          were set at model initialization. Other fields with value `None`
          are ignored.
        * Fields in `self.additional_properties` are added to the output dict.
        """
        excluded_fields: Set[str] = set([
            "additional_properties",
        ])

        _dict = self.model_dump(
            by_alias=True,
            exclude=excluded_fields,
            exclude_none=True,
        )
        # override the default output from pydantic by calling `to_dict()` of each item in input_mappings (list)
        _items = []
        if self.input_mappings:
            for _item_input_mappings in self.input_mappings:
                if _item_input_mappings:
                    _items.append(_item_input_mappings.to_dict())
            _dict['input_mappings'] = _items
        # puts key-value pairs in additional_properties in the top level
        if self.additional_properties is not None:
            for _key, _value in self.additional_properties.items():
                _dict[_key] = _value

        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of AlertApplicationConfigInput from a dict"""
        if obj is None:
            return None

        if not isinstance(obj, dict):
            return cls.model_validate(obj)

        _obj = cls.model_validate({
            "alert_id": obj.get("alert_id"),
            "execution_mode": obj.get("execution_mode"),
            "input_mappings": [AlertInputMapping.from_dict(_item) for _item in obj["input_mappings"]] if obj.get("input_mappings") is not None else None,
            "execution_phase": obj.get("execution_phase"),
            "priority": obj.get("priority") if obj.get("priority") is not None else 0
        })
        # store additional fields in additional_properties
        for _key in obj.keys():
            if _key not in cls.__properties:
                _obj.additional_properties[_key] = obj.get(_key)

        return _obj


