# 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, StrictBool, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from mixpeek.models.batch_options import BatchOptions
from mixpeek.models.cluster_options import ClusterOptions
from mixpeek.models.migration_type import MigrationType
from mixpeek.models.resource_filter import ResourceFilter
from mixpeek.models.retriever_options import RetrieverOptions
from mixpeek.models.shared_namespaces_migrations_models_feature_extractor_config import SharedNamespacesMigrationsModelsFeatureExtractorConfig
from mixpeek.models.taxonomy_options import TaxonomyOptions
from typing import Optional, Set
from typing_extensions import Self

class MigrationConfig(BaseModel):
    """
    Configuration for a namespace migration.
    """ # noqa: E501
    migration_type: MigrationType = Field(description="Type of migration to perform")
    source_namespace_id: StrictStr = Field(description="Source namespace ID")
    target_namespace_id: Optional[StrictStr] = Field(default=None, description="Target namespace ID (auto-generated if not provided)")
    target_namespace_name: Optional[StrictStr] = Field(default=None, description="Name for target namespace")
    feature_extractors: Optional[List[SharedNamespacesMigrationsModelsFeatureExtractorConfig]] = Field(default=None, description="New extractors to use (RE_EXTRACT only)")
    filters: Optional[ResourceFilter] = Field(default=None, description="Resource selection filters")
    batch_options: Optional[BatchOptions] = Field(default=None, description="Batch processing options")
    taxonomy_options: Optional[TaxonomyOptions] = Field(default=None, description="Taxonomy migration options")
    cluster_options: Optional[ClusterOptions] = Field(default=None, description="Cluster migration options")
    retriever_options: Optional[RetrieverOptions] = Field(default=None, description="Retriever migration options")
    preserve_resource_ids: Optional[StrictBool] = Field(default=False, description="Preserve original resource IDs in target")
    dry_run: Optional[StrictBool] = Field(default=False, description="Validate only, don't execute")
    webhook_url: Optional[StrictStr] = Field(default=None, description="Webhook URL for status notifications")
    __properties: ClassVar[List[str]] = ["migration_type", "source_namespace_id", "target_namespace_id", "target_namespace_name", "feature_extractors", "filters", "batch_options", "taxonomy_options", "cluster_options", "retriever_options", "preserve_resource_ids", "dry_run", "webhook_url"]

    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 MigrationConfig 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.
        """
        excluded_fields: Set[str] = set([
        ])

        _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 feature_extractors (list)
        _items = []
        if self.feature_extractors:
            for _item_feature_extractors in self.feature_extractors:
                if _item_feature_extractors:
                    _items.append(_item_feature_extractors.to_dict())
            _dict['feature_extractors'] = _items
        # override the default output from pydantic by calling `to_dict()` of filters
        if self.filters:
            _dict['filters'] = self.filters.to_dict()
        # override the default output from pydantic by calling `to_dict()` of batch_options
        if self.batch_options:
            _dict['batch_options'] = self.batch_options.to_dict()
        # override the default output from pydantic by calling `to_dict()` of taxonomy_options
        if self.taxonomy_options:
            _dict['taxonomy_options'] = self.taxonomy_options.to_dict()
        # override the default output from pydantic by calling `to_dict()` of cluster_options
        if self.cluster_options:
            _dict['cluster_options'] = self.cluster_options.to_dict()
        # override the default output from pydantic by calling `to_dict()` of retriever_options
        if self.retriever_options:
            _dict['retriever_options'] = self.retriever_options.to_dict()
        return _dict

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

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

        _obj = cls.model_validate({
            "migration_type": obj.get("migration_type"),
            "source_namespace_id": obj.get("source_namespace_id"),
            "target_namespace_id": obj.get("target_namespace_id"),
            "target_namespace_name": obj.get("target_namespace_name"),
            "feature_extractors": [SharedNamespacesMigrationsModelsFeatureExtractorConfig.from_dict(_item) for _item in obj["feature_extractors"]] if obj.get("feature_extractors") is not None else None,
            "filters": ResourceFilter.from_dict(obj["filters"]) if obj.get("filters") is not None else None,
            "batch_options": BatchOptions.from_dict(obj["batch_options"]) if obj.get("batch_options") is not None else None,
            "taxonomy_options": TaxonomyOptions.from_dict(obj["taxonomy_options"]) if obj.get("taxonomy_options") is not None else None,
            "cluster_options": ClusterOptions.from_dict(obj["cluster_options"]) if obj.get("cluster_options") is not None else None,
            "retriever_options": RetrieverOptions.from_dict(obj["retriever_options"]) if obj.get("retriever_options") is not None else None,
            "preserve_resource_ids": obj.get("preserve_resource_ids") if obj.get("preserve_resource_ids") is not None else False,
            "dry_run": obj.get("dry_run") if obj.get("dry_run") is not None else False,
            "webhook_url": obj.get("webhook_url")
        })
        return _obj


