# 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, field_validator
from typing import Any, ClassVar, Dict, List, Optional
from typing_extensions import Annotated
from typing import Optional, Set
from typing_extensions import Self

class FilenameRegexSource(BaseModel):
    """
    Extract value from filename using a regex pattern with capture groups.  Useful when metadata is encoded in filenames following a naming convention. The regex must contain exactly one capture group to extract the value.  Provider Compatibility: All providers (works on any filename)  Example filenames and patterns:     - \"marketing_Q4_2024_final.mp4\" with pattern \"^(\\w+)_Q\\d+_\" -> \"marketing\"     - \"user_12345_avatar.jpg\" with pattern \"user_(\\d+)_\" -> \"12345\"     - \"2024-01-15_meeting_notes.pdf\" with pattern \"^(\\d{4}-\\d{2}-\\d{2})\" -> \"2024-01-15\"     - \"IMG_20240115_143022.jpg\" with pattern \"IMG_(\\d{8})_\" -> \"20240115\"  Note: Use raw strings in Python or double-escape backslashes in JSON.  Attributes:     type: Must be \"filename_regex\" to identify this source type     pattern: Python regex with exactly one capture group     default: Optional default value if regex doesn't match
    """ # noqa: E501
    type: Optional[StrictStr] = Field(default='filename_regex', description="Source type identifier. Must be 'filename_regex' for regex extraction.")
    pattern: Annotated[str, Field(min_length=1, strict=True)] = Field(description="Python regex pattern with exactly one capture group. The captured group becomes the extracted value. Pattern is applied to the filename only (not full path). Use non-capturing groups (?:...) for grouping without capturing. Remember to escape backslashes in JSON (\\\\d instead of \\d).")
    default: Optional[StrictStr] = Field(default=None, description="Default value if regex doesn't match the filename. If None and regex doesn't match, the field is omitted from the object. Useful for ensuring a field always has a value.")
    __properties: ClassVar[List[str]] = ["type", "pattern", "default"]

    @field_validator('type')
    def type_validate_enum(cls, value):
        """Validates the enum"""
        if value is None:
            return value

        if value not in set(['filename_regex']):
            raise ValueError("must be one of enum values ('filename_regex')")
        return value

    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 FilenameRegexSource 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,
        )
        return _dict

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

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

        _obj = cls.model_validate({
            "type": obj.get("type") if obj.get("type") is not None else 'filename_regex',
            "pattern": obj.get("pattern"),
            "default": obj.get("default")
        })
        return _obj


