# coding: utf-8

"""
    Inventory

    No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)

    The version of the OpenAPI document: 1.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 datetime import datetime
from pydantic import BaseModel, ConfigDict, Field, StrictBool, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from legit_api_client.models.category import Category
from legit_api_client.models.issue_type import IssueType
from legit_api_client.models.origin_type import OriginType
from legit_api_client.models.scm_type import ScmType
from legit_api_client.models.severity import Severity
from typing import Optional, Set
from typing_extensions import Self

class PolicyDto(BaseModel):
    """
    PolicyDto
    """ # noqa: E501
    id: Optional[StrictStr] = None
    policy_name: Optional[StrictStr] = Field(default=None, alias="policyName")
    issue_type: Optional[IssueType] = Field(default=None, alias="issueType")
    severity: Optional[Severity] = None
    original_severity: Optional[Severity] = Field(default=None, alias="originalSeverity")
    category: Optional[Category] = None
    title: Optional[StrictStr] = None
    description: Optional[StrictStr] = None
    compliances: Optional[List[StrictStr]] = None
    is_disabled: Optional[StrictBool] = Field(default=None, alias="isDisabled")
    is_user_created: Optional[StrictBool] = Field(default=None, alias="isUserCreated")
    is_locked: Optional[StrictBool] = Field(default=None, alias="isLocked")
    target_origin_type: Optional[OriginType] = Field(default=None, alias="targetOriginType")
    target_scm_types: Optional[List[ScmType]] = Field(default=None, alias="targetScmTypes")
    open_issues_count: Optional[StrictInt] = Field(default=None, alias="openIssuesCount")
    definition_time: Optional[datetime] = Field(default=None, alias="definitionTime")
    source: Optional[StrictStr] = None
    remediation: Optional[StrictStr] = None
    __properties: ClassVar[List[str]] = ["id", "policyName", "issueType", "severity", "originalSeverity", "category", "title", "description", "compliances", "isDisabled", "isUserCreated", "isLocked", "targetOriginType", "targetScmTypes", "openIssuesCount", "definitionTime", "source", "remediation"]

    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 PolicyDto 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 id (nullable) is None
        # and model_fields_set contains the field
        if self.id is None and "id" in self.model_fields_set:
            _dict['id'] = None

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

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

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

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

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

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

        return _dict

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

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

        _obj = cls.model_validate({
            "id": obj.get("id"),
            "policyName": obj.get("policyName"),
            "issueType": obj.get("issueType"),
            "severity": obj.get("severity"),
            "originalSeverity": obj.get("originalSeverity"),
            "category": obj.get("category"),
            "title": obj.get("title"),
            "description": obj.get("description"),
            "compliances": obj.get("compliances"),
            "isDisabled": obj.get("isDisabled"),
            "isUserCreated": obj.get("isUserCreated"),
            "isLocked": obj.get("isLocked"),
            "targetOriginType": obj.get("targetOriginType"),
            "targetScmTypes": obj.get("targetScmTypes"),
            "openIssuesCount": obj.get("openIssuesCount"),
            "definitionTime": obj.get("definitionTime"),
            "source": obj.get("source"),
            "remediation": obj.get("remediation")
        })
        return _obj


