# coding: utf-8

"""
    Artifact Keeper API

    REST API for Artifact Keeper, an open-source universal artifact registry. Covers user management, repositories, artifacts, search, security scanning, SBOM, dependency tracking, SSO, analytics, monitoring, telemetry, lifecycle policies, plugins, edge nodes, migration, and administration. Format-specific protocol endpoints (npm, PyPI, Maven, Docker/OCI, etc.) are not included; those follow their respective upstream specifications.

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

class ComponentResponse(BaseModel):
    """
    ComponentResponse
    """ # noqa: E501
    id: StrictStr
    sbom_id: StrictStr
    name: StrictStr = Field(description="Component name.")
    version: Optional[StrictStr] = Field(default=None, description="Component version string.")
    purl: Optional[StrictStr] = Field(default=None, description="Package URL (purl) identifier.")
    cpe: Optional[StrictStr] = Field(default=None, description="Common Platform Enumeration identifier.")
    component_type: Optional[StrictStr] = Field(default=None, description="Component type (e.g. library, framework, application).")
    licenses: List[StrictStr] = Field(description="SPDX license identifiers associated with this component.")
    sha256: Optional[StrictStr] = Field(default=None, description="SHA-256 checksum of the component artifact.")
    sha1: Optional[StrictStr] = Field(default=None, description="SHA-1 checksum of the component artifact.")
    md5: Optional[StrictStr] = Field(default=None, description="MD5 checksum of the component artifact.")
    supplier: Optional[StrictStr] = Field(default=None, description="Organisation or individual that supplied the component.")
    author: Optional[StrictStr] = Field(default=None, description="Author of the component.")
    __properties: ClassVar[List[str]] = ["id", "sbom_id", "name", "version", "purl", "cpe", "component_type", "licenses", "sha256", "sha1", "md5", "supplier", "author"]

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

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

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

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

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

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

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

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

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

        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of ComponentResponse 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"),
            "sbom_id": obj.get("sbom_id"),
            "name": obj.get("name"),
            "version": obj.get("version"),
            "purl": obj.get("purl"),
            "cpe": obj.get("cpe"),
            "component_type": obj.get("component_type"),
            "licenses": obj.get("licenses"),
            "sha256": obj.get("sha256"),
            "sha1": obj.get("sha1"),
            "md5": obj.get("md5"),
            "supplier": obj.get("supplier"),
            "author": obj.get("author")
        })
        return _obj


