# 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.v1_hfr_star import V1HFRStar
from ourskyai_sda_api.models.v1_plate_solve_result import V1PlateSolveResult
from ourskyai_sda_api.models.v1_sip_coefficients import V1SIPCoefficients

class V1ImageMetadata(BaseModel):
    """
    V1ImageMetadata
    """
    id: StrictStr = Field(...)
    image_id: StrictStr = Field(..., alias="imageId")
    plate_solve_result: V1PlateSolveResult = Field(..., alias="plateSolveResult")
    input_stars: Optional[conlist(V1HFRStar)] = Field(None, alias="inputStars", description="Extracted star features from the image. Used as inputs to plate solving")
    sip_coefficients: Optional[V1SIPCoefficients] = Field(None, alias="sipCoefficients")
    photometric_zero_point: Optional[Union[StrictFloat, StrictInt]] = Field(None, alias="photometricZeroPoint", description="Photometric zero point offset. Add to instrumental magnitude (-2.5*log10(flux)) to get calibrated magnitude in standard photometric system.")
    created_at: datetime = Field(..., alias="createdAt")
    __properties = ["id", "imageId", "plateSolveResult", "inputStars", "sipCoefficients", "photometricZeroPoint", "createdAt"]

    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) -> V1ImageMetadata:
        """Create an instance of V1ImageMetadata 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 plate_solve_result
        if self.plate_solve_result:
            _dict['plateSolveResult'] = self.plate_solve_result.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in input_stars (list)
        _items = []
        if self.input_stars:
            for _item in self.input_stars:
                if _item:
                    _items.append(_item.to_dict())
            _dict['inputStars'] = _items
        # override the default output from pydantic by calling `to_dict()` of sip_coefficients
        if self.sip_coefficients:
            _dict['sipCoefficients'] = self.sip_coefficients.to_dict()
        return _dict

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

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

        _obj = V1ImageMetadata.parse_obj({
            "id": obj.get("id"),
            "image_id": obj.get("imageId"),
            "plate_solve_result": V1PlateSolveResult.from_dict(obj.get("plateSolveResult")) if obj.get("plateSolveResult") is not None else None,
            "input_stars": [V1HFRStar.from_dict(_item) for _item in obj.get("inputStars")] if obj.get("inputStars") is not None else None,
            "sip_coefficients": V1SIPCoefficients.from_dict(obj.get("sipCoefficients")) if obj.get("sipCoefficients") is not None else None,
            "photometric_zero_point": obj.get("photometricZeroPoint"),
            "created_at": obj.get("createdAt")
        })
        return _obj


