# 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](#tag/satellite-targets/GET/v1/satellite-targets) endpoint. Copy the id of the target you want to observe. 2. Create an organization target with the [organization target](#tag/organization-targets/GET/v1/organization-targets) endpoint. Use the id copied from above. 3. Create a webhook with the [webhook](#tag/webhooks/POST/v1/communications/webhook) endpoint to receive OSRs automatically (preferred) or use the [OSRs](#tag/observation-sequence-results/GET/v1/observation-sequence-results) endpoint to poll for OSRs.  Check out our [examples](https://github.com/ourskyai/oursky-examples) repository to see usage in each language.

    The version of the OpenAPI document: 1.3.9821
    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 List, Optional, Union
from pydantic import BaseModel, Field, StrictFloat, StrictInt, StrictStr, conlist
from ourskyai_sda_api.models.astrometric_offsets import AstrometricOffsets
from ourskyai_sda_api.models.observation_bounding_box import ObservationBoundingBox
from ourskyai_sda_api.models.v1_observation_feature import V1ObservationFeature

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")
    jpg_url: Optional[StrictStr] = Field(None, alias="jpgUrl")
    ra: Union[StrictFloat, StrictInt] = Field(..., description="The un-corrected apparent right ascension in degrees and EME2000 frame at the ground station")
    dec: Union[StrictFloat, StrictInt] = Field(..., description="The un-corrected apparent declination in degrees and EME2000 frame at the ground station")
    corrected_ra: Optional[Union[StrictFloat, StrictInt]] = Field(None, alias="correctedRa", description="The measured right ascension calibrated for stellar aberration in degrees and EME2000 frame")
    corrected_dec: Optional[Union[StrictFloat, StrictInt]] = Field(None, alias="correctedDec", description="The measured declination calibrated for stellar aberration in degrees and EME2000 frame")
    bounding_box: Optional[ObservationBoundingBox] = Field(None, alias="boundingBox")
    timestamp: datetime = Field(...)
    timing_accuracy: Union[StrictFloat, StrictInt] = Field(..., alias="timingAccuracy", description="Timestamps for this image are considered to be accurate to within +/- this value in seconds")
    apparent_magnitude: Optional[Union[StrictFloat, StrictInt]] = Field(None, alias="apparentMagnitude", description="BETA: the apparent magnitude of the target at the time of the observation")
    solar_phase_angle: Optional[Union[StrictFloat, StrictInt]] = Field(None, alias="solarPhaseAngle", description="BETA: the solar phase angle, defined as the angle between the target->observer and target->sun vectors, in degrees at the time of observation")
    solar_eq_phase_angle: Optional[Union[StrictFloat, StrictInt]] = Field(None, alias="solarEqPhaseAngle", description="BETA: the solar equatorial phase angle, defined as the solar phase angle in the equatorial plane, in degrees at the time of observation")
    geolat: Optional[Union[StrictFloat, StrictInt]] = Field(None, description="BETA: GEO latitude in degrees, if applicable")
    geolon: Optional[Union[StrictFloat, StrictInt]] = Field(None, description="BETA: GEO longitude in degrees, if applicable")
    distance_from_prediction: Optional[Union[StrictFloat, StrictInt]] = Field(None, alias="distanceFromPrediction", description="The distance from the predicted location in arcseconds (using SGP4 propagation)")
    features: Optional[conlist(V1ObservationFeature)] = None
    __properties = ["imageId", "astrometricOffsets", "imageUrl", "jpgUrl", "ra", "dec", "correctedRa", "correctedDec", "boundingBox", "timestamp", "timingAccuracy", "apparentMagnitude", "solarPhaseAngle", "solarEqPhaseAngle", "geolat", "geolon", "distanceFromPrediction", "features"]

    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()
        # override the default output from pydantic by calling `to_dict()` of bounding_box
        if self.bounding_box:
            _dict['boundingBox'] = self.bounding_box.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in features (list)
        _items = []
        if self.features:
            for _item in self.features:
                if _item:
                    _items.append(_item.to_dict())
            _dict['features'] = _items
        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"),
            "jpg_url": obj.get("jpgUrl"),
            "ra": obj.get("ra"),
            "dec": obj.get("dec"),
            "corrected_ra": obj.get("correctedRa"),
            "corrected_dec": obj.get("correctedDec"),
            "bounding_box": ObservationBoundingBox.from_dict(obj.get("boundingBox")) if obj.get("boundingBox") is not None else None,
            "timestamp": obj.get("timestamp"),
            "timing_accuracy": obj.get("timingAccuracy"),
            "apparent_magnitude": obj.get("apparentMagnitude"),
            "solar_phase_angle": obj.get("solarPhaseAngle"),
            "solar_eq_phase_angle": obj.get("solarEqPhaseAngle"),
            "geolat": obj.get("geolat"),
            "geolon": obj.get("geolon"),
            "distance_from_prediction": obj.get("distanceFromPrediction"),
            "features": [V1ObservationFeature.from_dict(_item) for _item in obj.get("features")] if obj.get("features") is not None else None
        })
        return _obj


