# coding: utf-8

"""
    Kubeflow Spark Operator OpenAPI Spec

    No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)

    The version of the OpenAPI document: unversioned
    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 pydantic import BaseModel, ConfigDict, Field, StrictBool, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from kubeflow_spark_api.models.spark_v1beta2_spark_application_spec import SparkV1beta2SparkApplicationSpec
from typing import Optional, Set
from typing_extensions import Self

class SparkV1beta2ScheduledSparkApplicationSpec(BaseModel):
    """
    ScheduledSparkApplicationSpec defines the desired state of ScheduledSparkApplication.
    """ # noqa: E501
    concurrency_policy: Optional[StrictStr] = Field(default=None, description="ConcurrencyPolicy is the policy governing concurrent SparkApplication runs.", alias="concurrencyPolicy")
    failed_run_history_limit: Optional[StrictInt] = Field(default=None, description="FailedRunHistoryLimit is the number of past failed runs of the application to keep. Defaults to 1.", alias="failedRunHistoryLimit")
    schedule: StrictStr = Field(description="Schedule is a cron schedule on which the application should run.")
    successful_run_history_limit: Optional[StrictInt] = Field(default=None, description="SuccessfulRunHistoryLimit is the number of past successful runs of the application to keep. Defaults to 1.", alias="successfulRunHistoryLimit")
    suspend: Optional[StrictBool] = Field(default=None, description="Suspend is a flag telling the controller to suspend subsequent runs of the application if set to true. Defaults to false.")
    template: SparkV1beta2SparkApplicationSpec = Field(description="Template is a template from which SparkApplication instances can be created.")
    time_zone: Optional[StrictStr] = Field(default=None, description="TimeZone is the time zone in which the cron schedule will be interpreted in. This value is passed to time.LoadLocation, so it must be either \"Local\", \"UTC\", or a valid IANA location name e.g. \"America/New_York\". Defaults to \"Local\".", alias="timeZone")
    __properties: ClassVar[List[str]] = ["concurrencyPolicy", "failedRunHistoryLimit", "schedule", "successfulRunHistoryLimit", "suspend", "template", "timeZone"]

    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 SparkV1beta2ScheduledSparkApplicationSpec 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 template
        if self.template:
            _dict['template'] = self.template.to_dict()
        return _dict

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

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

        _obj = cls.model_validate({
            "concurrencyPolicy": obj.get("concurrencyPolicy"),
            "failedRunHistoryLimit": obj.get("failedRunHistoryLimit"),
            "schedule": obj.get("schedule") if obj.get("schedule") is not None else '',
            "successfulRunHistoryLimit": obj.get("successfulRunHistoryLimit"),
            "suspend": obj.get("suspend"),
            "template": SparkV1beta2SparkApplicationSpec.from_dict(obj["template"]) if obj.get("template") is not None else None,
            "timeZone": obj.get("timeZone")
        })
        return _obj


