# coding: utf-8

"""
    ACROSS Server

    Server providing tools and utilities for various NASA missions to aid in coordination of large observation efforts.

    The version of the OpenAPI document: 1.4.0
    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 pydantic import BaseModel, ConfigDict, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from across.sdk.v1.models.date_range import DateRange
from across.sdk.v1.models.observation import Observation
from across.sdk.v1.models.schedule_fidelity import ScheduleFidelity
from across.sdk.v1.models.schedule_status import ScheduleStatus
from typing import Optional, Set
from typing_extensions import Self

class Schedule(BaseModel):
    """
    A Pydantic model class representing a created observing schedule for a telescope.  Parameters ---------- id : UUID     Schedule id observations : list[schemas.Observation]     A list of observations for the schedule created_on : datetime     Datetime the schedule was created created_by_id : UUID     AuthUser id checksum : str     Unique string representation of the schedule and observations  Notes ----- Inherits from ScheduleBase  Methods ------- create_checksum(schedule: ScheduleModel) -> str     Static method that creates the checksum from the schedule metadata and observation list metadata from_orm(schedule: ScheduleModel) -> Schedule     Static method that instantiates this class from a schedule database record
    """ # noqa: E501
    telescope_id: StrictStr
    name: StrictStr
    date_range: DateRange
    status: ScheduleStatus
    external_id: Optional[StrictStr] = None
    fidelity: Optional[ScheduleFidelity] = None
    id: StrictStr
    observations: Optional[List[Observation]]
    observation_count: StrictInt
    created_on: datetime
    created_by_id: Optional[StrictStr]
    checksum: Optional[StrictStr] = ''
    __properties: ClassVar[List[str]] = ["telescope_id", "name", "date_range", "status", "external_id", "fidelity", "id", "observations", "observation_count", "created_on", "created_by_id", "checksum"]

    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 Schedule 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,
        )
        # override the default output from pydantic by calling `to_dict()` of date_range
        if self.date_range:
            _dict['date_range'] = self.date_range.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in observations (list)
        _items = []
        if self.observations:
            for _item_observations in self.observations:
                if _item_observations:
                    _items.append(_item_observations.to_dict())
            _dict['observations'] = _items
        # set to None if external_id (nullable) is None
        # and model_fields_set contains the field
        if self.external_id is None and "external_id" in self.model_fields_set:
            _dict['external_id'] = None

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

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

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

        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of Schedule from a dict"""
        if obj is None:
            return None

        if not isinstance(obj, dict):
            return cls.model_validate(obj)

        _obj = cls.model_validate({
            "telescope_id": obj.get("telescope_id"),
            "name": obj.get("name"),
            "date_range": DateRange.from_dict(obj["date_range"]) if obj.get("date_range") is not None else None,
            "status": obj.get("status"),
            "external_id": obj.get("external_id"),
            "fidelity": obj.get("fidelity"),
            "id": obj.get("id"),
            "observations": [Observation.from_dict(_item) for _item in obj["observations"]] if obj.get("observations") is not None else None,
            "observation_count": obj.get("observation_count"),
            "created_on": obj.get("created_on"),
            "created_by_id": obj.get("created_by_id"),
            "checksum": obj.get("checksum") if obj.get("checksum") is not None else ''
        })
        return _obj


