# coding: utf-8

"""
    Asteroid Agents API

    Version 1 of the Asteroid Agents API

    The version of the OpenAPI document: v1.0.0
    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 typing_extensions import Annotated
from asteroid_odyssey.agents_v1_gen.models.cookie import Cookie
from asteroid_odyssey.agents_v1_gen.models.country_code import CountryCode
from asteroid_odyssey.agents_v1_gen.models.credential import Credential
from asteroid_odyssey.agents_v1_gen.models.proxy_type import ProxyType
from typing import Optional, Set
from typing_extensions import Self

class CreateAgentProfileRequest(BaseModel):
    """
    CreateAgentProfileRequest
    """ # noqa: E501
    name: Annotated[str, Field(min_length=1, strict=True, max_length=255)] = Field(description="Name of the agent profile (must be unique within organization)")
    description: Annotated[str, Field(strict=True, max_length=1000)] = Field(description="Description of the agent profile")
    organization_id: StrictStr = Field(description="The ID of the organization that the agent profile belongs to")
    proxy_cc: CountryCode
    proxy_type: ProxyType
    captcha_solver_active: StrictBool = Field(description="Whether the captcha solver should be active for this profile")
    sticky_ip: StrictBool = Field(description="Whether the same IP address should be used for all executions of this profile")
    credentials: List[Credential] = Field(description="Optional list of credentials to create with the profile")
    cookies: List[Cookie] = Field(description="Optional list of cookies to create with the profile")
    tracing_snapshots: Optional[StrictBool] = Field(default=True, description="Whether to enable tracing snapshots for the profile")
    extra_stealth: Optional[StrictBool] = Field(default=False, description="Whether to enable extra stealth for the profile")
    __properties: ClassVar[List[str]] = ["name", "description", "organization_id", "proxy_cc", "proxy_type", "captcha_solver_active", "sticky_ip", "credentials", "cookies", "tracing_snapshots", "extra_stealth"]

    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 CreateAgentProfileRequest 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 credentials (list)
        _items = []
        if self.credentials:
            for _item_credentials in self.credentials:
                if _item_credentials:
                    _items.append(_item_credentials.to_dict())
            _dict['credentials'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in cookies (list)
        _items = []
        if self.cookies:
            for _item_cookies in self.cookies:
                if _item_cookies:
                    _items.append(_item_cookies.to_dict())
            _dict['cookies'] = _items
        return _dict

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

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

        _obj = cls.model_validate({
            "name": obj.get("name"),
            "description": obj.get("description"),
            "organization_id": obj.get("organization_id"),
            "proxy_cc": obj.get("proxy_cc"),
            "proxy_type": obj.get("proxy_type"),
            "captcha_solver_active": obj.get("captcha_solver_active") if obj.get("captcha_solver_active") is not None else False,
            "sticky_ip": obj.get("sticky_ip") if obj.get("sticky_ip") is not None else False,
            "credentials": [Credential.from_dict(_item) for _item in obj["credentials"]] if obj.get("credentials") is not None else None,
            "cookies": [Cookie.from_dict(_item) for _item in obj["cookies"]] if obj.get("cookies") is not None else None,
            "tracing_snapshots": obj.get("tracing_snapshots") if obj.get("tracing_snapshots") is not None else True,
            "extra_stealth": obj.get("extra_stealth") if obj.get("extra_stealth") is not None else False
        })
        return _obj


