# coding: utf-8

"""
    Cyberwave API

    Cyberwave platform REST API. Use 'Bearer YOUR_TOKEN' for authentication.

    The version of the OpenAPI document: 1.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, StrictBool, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from cyberwave.rest.models.value import Value
from typing import Optional, Set
from typing_extensions import Self

class OpportunityUpdateSchema(BaseModel):
    """
    OpportunityUpdateSchema
    """ # noqa: E501
    name: Optional[StrictStr] = None
    description: Optional[StrictStr] = None
    opportunity_type: Optional[StrictStr] = None
    stage: Optional[StrictStr] = None
    value: Optional[Value] = None
    contact_name: Optional[StrictStr] = None
    contact_email: Optional[StrictStr] = None
    company_name: Optional[StrictStr] = None
    expected_close_date: Optional[StrictStr] = None
    notes: Optional[StrictStr] = None
    metadata: Optional[Dict[str, Any]] = None
    year: Optional[StrictInt] = None
    is_archived: Optional[StrictBool] = None
    sort_order: Optional[StrictInt] = None
    workspace_uuid: Optional[StrictStr] = None
    assigned_to_uuid: Optional[StrictStr] = None
    __properties: ClassVar[List[str]] = ["name", "description", "opportunity_type", "stage", "value", "contact_name", "contact_email", "company_name", "expected_close_date", "notes", "metadata", "year", "is_archived", "sort_order", "workspace_uuid", "assigned_to_uuid"]

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of OpportunityUpdateSchema 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"),
            "opportunity_type": obj.get("opportunity_type"),
            "stage": obj.get("stage"),
            "value": Value.from_dict(obj["value"]) if obj.get("value") is not None else None,
            "contact_name": obj.get("contact_name"),
            "contact_email": obj.get("contact_email"),
            "company_name": obj.get("company_name"),
            "expected_close_date": obj.get("expected_close_date"),
            "notes": obj.get("notes"),
            "metadata": obj.get("metadata"),
            "year": obj.get("year"),
            "is_archived": obj.get("is_archived"),
            "sort_order": obj.get("sort_order"),
            "workspace_uuid": obj.get("workspace_uuid"),
            "assigned_to_uuid": obj.get("assigned_to_uuid")
        })
        return _obj


