# coding: utf-8

"""
    kameleo-local-api

    You can use the following API endpoints to communicate with the local running Kameleo programmatically.

    The version of the OpenAPI document: 4.3.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, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from typing_extensions import Annotated
from typing import Optional, Set
from typing_extensions import Self

class CookieRequest(BaseModel):
    """
    CookieRequest
    """ # noqa: E501
    domain: Annotated[str, Field(min_length=1, strict=True)] = Field(description="The domain attribute signifies the domain for which the cookie is valid and can be submitted with every request for this domain or its  subdomains. If this attribute is not specified, then the hostname of the originating server is used as the default value.")
    name: StrictStr = Field(description="The name for the Cookie.")
    path: Annotated[str, Field(min_length=1, strict=True)] = Field(description="The path attribute indicates a URL path that must exist in the requested URL in order to send the Cookie header. The %x2F (\"/\") character  is considered a directory separator, and subdirectories match as well.")
    value: StrictStr = Field(description="The value of the Cookie.")
    host_only: Optional[StrictBool] = Field(default=None, description="Host Only cookie means that the cookie should be handled by the browser to the server only to the same host/server that firstly sent it to  the browser.", alias="hostOnly")
    http_only: Optional[StrictBool] = Field(default=None, description="When this attribute is set, client-side scripts are not allowed to access the cookie.", alias="httpOnly")
    secure: Optional[StrictBool] = Field(default=None, description="A cookie with the Secure attribute is sent to the server only with an encrypted request over the HTTPS protocol, never with unsecured HTTP,  and therefore can't easily be accessed by a man-in-the-middle attacker. Insecure sites (with http: in the URL) can't set cookies with the  Secure attribute.")
    same_site: Optional[StrictStr] = Field(default=None, description="The sameSite attribute lets servers require that a cookie shouldn't be sent with cross-origin requests (where Site is defined by the  registrable domain), which provides some protection against cross-site request forgery attacks (CSRF).  It takes three possible values: Strict, Lax, and None.With Strict, the cookie is sent only to the same site as the one that originated it;  Lax is similar, with an exception for when the user navigates to a URL from an external site, such as by following a link; None has no  restrictions on cross-site requests.", alias="sameSite")
    expiration_date: Optional[StrictInt] = Field(default=None, description="This attribute is used to set persistent cookies. It signifies how long the browser should use the persistent cookie and when the cookie  should be deleted.  If this attribute is not specified, then the lifetime of the cookie is the same as that of browser session, i.e.it will be a non-persistent  cookie.", alias="expirationDate")
    __properties: ClassVar[List[str]] = ["domain", "name", "path", "value", "hostOnly", "httpOnly", "secure", "sameSite", "expirationDate"]

    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 CookieRequest 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,
        )
        # set to None if same_site (nullable) is None
        # and model_fields_set contains the field
        if self.same_site is None and "same_site" in self.model_fields_set:
            _dict['sameSite'] = None

        # set to None if expiration_date (nullable) is None
        # and model_fields_set contains the field
        if self.expiration_date is None and "expiration_date" in self.model_fields_set:
            _dict['expirationDate'] = None

        return _dict

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

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

        _obj = cls.model_validate({
            "domain": obj.get("domain"),
            "name": obj.get("name"),
            "path": obj.get("path"),
            "value": obj.get("value"),
            "hostOnly": obj.get("hostOnly"),
            "httpOnly": obj.get("httpOnly"),
            "secure": obj.get("secure"),
            "sameSite": obj.get("sameSite"),
            "expirationDate": obj.get("expirationDate")
        })
        return _obj


