# coding: utf-8

"""
    OurSky SDA

    The basic flow for a new organization is as follows: 1. View the available satellite targets with the [satellite targets](#operation/v1GetSatelliteTargets) endpoint. Copy the id of the target you want to observe. 2. Create an organization target with the [organization target](#operation/v1CreateOrganizationTarget) endpoint. Use the id copied from above. 3. Create a webhook with the [webhook](#operation/v1CreateWebhookConfiguration) endpoint to receive TDMs automatically (preferred) or use the [tdms](#operation/v1GetTdms) endpoint to poll for TDMs.

    The version of the OpenAPI document: 1.3.1905
    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 typing import Optional, Union
from pydantic import BaseModel, Field, StrictFloat, StrictInt, StrictStr
from ourskyai_sda_api.models.astrometric_offsets import AstrometricOffsets

class ObservationResult(BaseModel):
    """
    A single observation result. This is a 1:1 mapping with a single image  # noqa: E501
    """
    image_id: StrictStr = Field(..., alias="imageId")
    astrometric_offsets: AstrometricOffsets = Field(..., alias="astrometricOffsets")
    image_url: Optional[StrictStr] = Field(None, alias="imageUrl")
    ra: Union[StrictFloat, StrictInt] = Field(...)
    dec: Union[StrictFloat, StrictInt] = Field(...)
    timestamp: datetime = Field(...)
    apparent_magnitude: Optional[Union[StrictFloat, StrictInt]] = Field(None, alias="apparentMagnitude", description="BETA: the apparent magnitude of the target at the time of the observation")
    __properties = ["imageId", "astrometricOffsets", "imageUrl", "ra", "dec", "timestamp", "apparentMagnitude"]

    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) -> ObservationResult:
        """Create an instance of ObservationResult 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)
        # override the default output from pydantic by calling `to_dict()` of astrometric_offsets
        if self.astrometric_offsets:
            _dict['astrometricOffsets'] = self.astrometric_offsets.to_dict()
        return _dict

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

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

        _obj = ObservationResult.parse_obj({
            "image_id": obj.get("imageId"),
            "astrometric_offsets": AstrometricOffsets.from_dict(obj.get("astrometricOffsets")) if obj.get("astrometricOffsets") is not None else None,
            "image_url": obj.get("imageUrl"),
            "ra": obj.get("ra"),
            "dec": obj.get("dec"),
            "timestamp": obj.get("timestamp"),
            "apparent_magnitude": obj.get("apparentMagnitude")
        })
        return _obj


