# coding: utf-8

"""
    Sonatype Lifecycle Public REST API

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

    The version of the OpenAPI document: 1.197.0-01
    Contact: community@sonatype.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 datetime import datetime
from pydantic import BaseModel, ConfigDict, Field, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from sonatype_iq_api_client.models.api_license_legal_copyright_dto import ApiLicenseLegalCopyrightDTO
from sonatype_iq_api_client.models.api_license_legal_file_dto import ApiLicenseLegalFileDTO
from sonatype_iq_api_client.models.api_license_legal_obligation_dto import ApiLicenseLegalObligationDTO
from sonatype_iq_api_client.models.api_license_threat_dtov2 import ApiLicenseThreatDTOV2
from sonatype_iq_api_client.models.component_obligation_attribution_dto import ComponentObligationAttributionDTO
from sonatype_iq_api_client.models.legal_source_link_dto import LegalSourceLinkDTO
from typing import Optional, Set
from typing_extensions import Self

class ApiLicenseLegalDataDTO(BaseModel):
    """
    ApiLicenseLegalDataDTO
    """ # noqa: E501
    attributions: Optional[List[ComponentObligationAttributionDTO]] = None
    component_copyright_id: Optional[StrictStr] = Field(default=None, alias="componentCopyrightId")
    component_copyright_last_updated_at: Optional[datetime] = Field(default=None, alias="componentCopyrightLastUpdatedAt")
    component_copyright_last_updated_by_username: Optional[StrictStr] = Field(default=None, alias="componentCopyrightLastUpdatedByUsername")
    component_copyright_scope_owner_id: Optional[StrictStr] = Field(default=None, alias="componentCopyrightScopeOwnerId")
    component_licenses_id: Optional[StrictStr] = Field(default=None, alias="componentLicensesId")
    component_licenses_last_updated_at: Optional[datetime] = Field(default=None, alias="componentLicensesLastUpdatedAt")
    component_licenses_last_updated_by_username: Optional[StrictStr] = Field(default=None, alias="componentLicensesLastUpdatedByUsername")
    component_licenses_scope_owner_id: Optional[StrictStr] = Field(default=None, alias="componentLicensesScopeOwnerId")
    component_notices_id: Optional[StrictStr] = Field(default=None, alias="componentNoticesId")
    component_notices_last_updated_at: Optional[datetime] = Field(default=None, alias="componentNoticesLastUpdatedAt")
    component_notices_last_updated_by_username: Optional[StrictStr] = Field(default=None, alias="componentNoticesLastUpdatedByUsername")
    component_notices_scope_owner_id: Optional[StrictStr] = Field(default=None, alias="componentNoticesScopeOwnerId")
    copyrights: Optional[List[ApiLicenseLegalCopyrightDTO]] = None
    declared_licenses: Optional[List[StrictStr]] = Field(default=None, alias="declaredLicenses")
    effective_license_status: Optional[StrictStr] = Field(default=None, alias="effectiveLicenseStatus")
    effective_licenses: Optional[List[StrictStr]] = Field(default=None, alias="effectiveLicenses")
    highest_effective_license_threat_group: Optional[ApiLicenseThreatDTOV2] = Field(default=None, alias="highestEffectiveLicenseThreatGroup")
    license_files: Optional[List[ApiLicenseLegalFileDTO]] = Field(default=None, alias="licenseFiles")
    notice_files: Optional[List[ApiLicenseLegalFileDTO]] = Field(default=None, alias="noticeFiles")
    obligations: Optional[List[ApiLicenseLegalObligationDTO]] = None
    observed_licenses: Optional[List[StrictStr]] = Field(default=None, alias="observedLicenses")
    source_links: Optional[List[LegalSourceLinkDTO]] = Field(default=None, alias="sourceLinks")
    __properties: ClassVar[List[str]] = ["attributions", "componentCopyrightId", "componentCopyrightLastUpdatedAt", "componentCopyrightLastUpdatedByUsername", "componentCopyrightScopeOwnerId", "componentLicensesId", "componentLicensesLastUpdatedAt", "componentLicensesLastUpdatedByUsername", "componentLicensesScopeOwnerId", "componentNoticesId", "componentNoticesLastUpdatedAt", "componentNoticesLastUpdatedByUsername", "componentNoticesScopeOwnerId", "copyrights", "declaredLicenses", "effectiveLicenseStatus", "effectiveLicenses", "highestEffectiveLicenseThreatGroup", "licenseFiles", "noticeFiles", "obligations", "observedLicenses", "sourceLinks"]

    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 ApiLicenseLegalDataDTO 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 attributions (list)
        _items = []
        if self.attributions:
            for _item_attributions in self.attributions:
                if _item_attributions:
                    _items.append(_item_attributions.to_dict())
            _dict['attributions'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in copyrights (list)
        _items = []
        if self.copyrights:
            for _item_copyrights in self.copyrights:
                if _item_copyrights:
                    _items.append(_item_copyrights.to_dict())
            _dict['copyrights'] = _items
        # override the default output from pydantic by calling `to_dict()` of highest_effective_license_threat_group
        if self.highest_effective_license_threat_group:
            _dict['highestEffectiveLicenseThreatGroup'] = self.highest_effective_license_threat_group.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in license_files (list)
        _items = []
        if self.license_files:
            for _item_license_files in self.license_files:
                if _item_license_files:
                    _items.append(_item_license_files.to_dict())
            _dict['licenseFiles'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in notice_files (list)
        _items = []
        if self.notice_files:
            for _item_notice_files in self.notice_files:
                if _item_notice_files:
                    _items.append(_item_notice_files.to_dict())
            _dict['noticeFiles'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in obligations (list)
        _items = []
        if self.obligations:
            for _item_obligations in self.obligations:
                if _item_obligations:
                    _items.append(_item_obligations.to_dict())
            _dict['obligations'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in source_links (list)
        _items = []
        if self.source_links:
            for _item_source_links in self.source_links:
                if _item_source_links:
                    _items.append(_item_source_links.to_dict())
            _dict['sourceLinks'] = _items
        return _dict

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

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

        _obj = cls.model_validate({
            "attributions": [ComponentObligationAttributionDTO.from_dict(_item) for _item in obj["attributions"]] if obj.get("attributions") is not None else None,
            "componentCopyrightId": obj.get("componentCopyrightId"),
            "componentCopyrightLastUpdatedAt": obj.get("componentCopyrightLastUpdatedAt"),
            "componentCopyrightLastUpdatedByUsername": obj.get("componentCopyrightLastUpdatedByUsername"),
            "componentCopyrightScopeOwnerId": obj.get("componentCopyrightScopeOwnerId"),
            "componentLicensesId": obj.get("componentLicensesId"),
            "componentLicensesLastUpdatedAt": obj.get("componentLicensesLastUpdatedAt"),
            "componentLicensesLastUpdatedByUsername": obj.get("componentLicensesLastUpdatedByUsername"),
            "componentLicensesScopeOwnerId": obj.get("componentLicensesScopeOwnerId"),
            "componentNoticesId": obj.get("componentNoticesId"),
            "componentNoticesLastUpdatedAt": obj.get("componentNoticesLastUpdatedAt"),
            "componentNoticesLastUpdatedByUsername": obj.get("componentNoticesLastUpdatedByUsername"),
            "componentNoticesScopeOwnerId": obj.get("componentNoticesScopeOwnerId"),
            "copyrights": [ApiLicenseLegalCopyrightDTO.from_dict(_item) for _item in obj["copyrights"]] if obj.get("copyrights") is not None else None,
            "declaredLicenses": obj.get("declaredLicenses"),
            "effectiveLicenseStatus": obj.get("effectiveLicenseStatus"),
            "effectiveLicenses": obj.get("effectiveLicenses"),
            "highestEffectiveLicenseThreatGroup": ApiLicenseThreatDTOV2.from_dict(obj["highestEffectiveLicenseThreatGroup"]) if obj.get("highestEffectiveLicenseThreatGroup") is not None else None,
            "licenseFiles": [ApiLicenseLegalFileDTO.from_dict(_item) for _item in obj["licenseFiles"]] if obj.get("licenseFiles") is not None else None,
            "noticeFiles": [ApiLicenseLegalFileDTO.from_dict(_item) for _item in obj["noticeFiles"]] if obj.get("noticeFiles") is not None else None,
            "obligations": [ApiLicenseLegalObligationDTO.from_dict(_item) for _item in obj["obligations"]] if obj.get("obligations") is not None else None,
            "observedLicenses": obj.get("observedLicenses"),
            "sourceLinks": [LegalSourceLinkDTO.from_dict(_item) for _item in obj["sourceLinks"]] if obj.get("sourceLinks") is not None else None
        })
        return _obj


