# coding: utf-8

"""
    Kubernetes

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

    The version of the OpenAPI document: release-1.29
    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 typing import Optional
from pydantic import BaseModel, Field, StrictBool, StrictInt, StrictStr
from .v1_job_template_spec import V1JobTemplateSpec

class V1CronJobSpec(BaseModel):
    """
    CronJobSpec describes how the job execution will look like and when it will actually run.  # noqa: E501
    """
    concurrency_policy: Optional[StrictStr] = Field(None, alias="concurrencyPolicy", description="Specifies how to treat concurrent executions of a Job. Valid values are:  - \"Allow\" (default): allows CronJobs to run concurrently; - \"Forbid\": forbids concurrent runs, skipping next run if previous run hasn't finished yet; - \"Replace\": cancels currently running job and replaces it with a new one")
    failed_jobs_history_limit: Optional[StrictInt] = Field(None, alias="failedJobsHistoryLimit", description="The number of failed finished jobs to retain. Value must be non-negative integer. Defaults to 1.")
    job_template: V1JobTemplateSpec = Field(..., alias="jobTemplate")
    schedule: StrictStr = Field(..., description="The schedule in Cron format, see https://en.wikipedia.org/wiki/Cron.")
    starting_deadline_seconds: Optional[StrictInt] = Field(None, alias="startingDeadlineSeconds", description="Optional deadline in seconds for starting the job if it misses scheduled time for any reason.  Missed jobs executions will be counted as failed ones.")
    successful_jobs_history_limit: Optional[StrictInt] = Field(None, alias="successfulJobsHistoryLimit", description="The number of successful finished jobs to retain. Value must be non-negative integer. Defaults to 3.")
    suspend: Optional[StrictBool] = Field(None, description="This flag tells the controller to suspend subsequent executions, it does not apply to already started executions.  Defaults to false.")
    time_zone: Optional[StrictStr] = Field(None, alias="timeZone", description="The time zone name for the given schedule, see https://en.wikipedia.org/wiki/List_of_tz_database_time_zones. If not specified, this will default to the time zone of the kube-controller-manager process. The set of valid time zone names and the time zone offset is loaded from the system-wide time zone database by the API server during CronJob validation and the controller manager during execution. If no system-wide time zone database can be found a bundled version of the database is used instead. If the time zone name becomes invalid during the lifetime of a CronJob or due to a change in host configuration, the controller will stop creating new new Jobs and will create a system event with the reason UnknownTimeZone. More information can be found in https://kubernetes.io/docs/concepts/workloads/controllers/cron-jobs/#time-zones")
    __properties = ["concurrencyPolicy", "failedJobsHistoryLimit", "jobTemplate", "schedule", "startingDeadlineSeconds", "successfulJobsHistoryLimit", "suspend", "timeZone"]

    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) -> V1CronJobSpec:
        """Create an instance of V1CronJobSpec 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 job_template
        if self.job_template:
            _dict['jobTemplate'] = self.job_template.to_dict()
        return _dict

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

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

        _obj = V1CronJobSpec.parse_obj({
            "concurrency_policy": obj.get("concurrencyPolicy"),
            "failed_jobs_history_limit": obj.get("failedJobsHistoryLimit"),
            "job_template": V1JobTemplateSpec.from_dict(obj.get("jobTemplate")) if obj.get("jobTemplate") is not None else None,
            "schedule": obj.get("schedule"),
            "starting_deadline_seconds": obj.get("startingDeadlineSeconds"),
            "successful_jobs_history_limit": obj.get("successfulJobsHistoryLimit"),
            "suspend": obj.get("suspend"),
            "time_zone": obj.get("timeZone")
        })
        return _obj


