# coding: utf-8

"""
HaploHub API

The HaploHub is a turnkey solution to securely store and interpret biomarkers, genetics, and 'omics data. Our customers use the HaploHub to:  * Store WGS, WES, low-pass, and array data with uniform REST interfaces to access variants  * Interpret genomic variants  * Generate risk scores for an individual  * Run the typical algorithms (phasing, imputation, etc.)  * Calculate 'biological age' or 'organ age' biomarkers  * Generate custom reports  The HaploHub platform is continually updated to remain at the forefront of scientific understanding.

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 json
import pprint
import re  # noqa: F401
from datetime import datetime
from typing import Optional, Union

from pydantic import BaseModel, Field, StrictFloat, StrictInt, StrictStr

from haplohub.models.most_similar_population import MostSimilarPopulation


class MemberPgsScoreSchema(BaseModel):
    """
    MemberPgsScoreSchema
    """

    id: StrictStr = Field(...)
    cohort_id: StrictStr = Field(...)
    member_id: StrictStr = Field(...)
    trait_id: StrictStr = Field(...)
    adjusted_z_score: Union[StrictFloat, StrictInt] = Field(...)
    percentile: Union[StrictFloat, StrictInt] = Field(...)
    relative_risk: Optional[Union[StrictFloat, StrictInt]] = None
    most_similar_population: MostSimilarPopulation = Field(...)
    source_algorithm_result_id: StrictStr = Field(...)
    time_created: datetime = Field(...)
    __properties = [
        "id",
        "cohort_id",
        "member_id",
        "trait_id",
        "adjusted_z_score",
        "percentile",
        "relative_risk",
        "most_similar_population",
        "source_algorithm_result_id",
        "time_created",
    ]

    class Config:
        """Pydantic configuration"""

        allow_population_by_field_name = True
        validate_assignment = True

    def to_str(self) -> str:
        """Returns the string representation of the model using alias"""
        return pprint.pformat(self.dict(by_alias=True))

    def to_json(self) -> str:
        """Returns the JSON representation of the model using alias"""
        return json.dumps(self.to_dict())

    @classmethod
    def from_json(cls, json_str: str) -> MemberPgsScoreSchema:
        """Create an instance of MemberPgsScoreSchema from a JSON string"""
        return cls.from_dict(json.loads(json_str))

    def to_dict(self):
        """Returns the dictionary representation of the model using alias"""
        _dict = self.dict(by_alias=True, exclude={}, exclude_none=True)
        # set to None if relative_risk (nullable) is None
        # and __fields_set__ contains the field
        if self.relative_risk is None and "relative_risk" in self.__fields_set__:
            _dict["relative_risk"] = None

        return _dict

    @classmethod
    def from_dict(cls, obj: dict) -> MemberPgsScoreSchema:
        """Create an instance of MemberPgsScoreSchema from a dict"""
        if obj is None:
            return None

        if not isinstance(obj, dict):
            return MemberPgsScoreSchema.parse_obj(obj)

        _obj = MemberPgsScoreSchema.parse_obj(
            {
                "id": obj.get("id"),
                "cohort_id": obj.get("cohort_id"),
                "member_id": obj.get("member_id"),
                "trait_id": obj.get("trait_id"),
                "adjusted_z_score": obj.get("adjusted_z_score"),
                "percentile": obj.get("percentile"),
                "relative_risk": obj.get("relative_risk"),
                "most_similar_population": obj.get("most_similar_population"),
                "source_algorithm_result_id": obj.get("source_algorithm_result_id"),
                "time_created": obj.get("time_created"),
            }
        )
        return _obj
