# coding: utf-8

"""
    SkyTorch 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, StrictStr, field_validator
from typing import Any, ClassVar, Dict, List, Optional
from skytorch.client.models.io_k8s_api_core_v1_lifecycle_handler import IoK8sApiCoreV1LifecycleHandler
from typing import Optional, Set
from typing_extensions import Self

class IoK8sApiCoreV1Lifecycle(BaseModel):
    """
    Lifecycle describes actions that the management system should take in response to container lifecycle events. For the PostStart and PreStop lifecycle handlers, management of the container blocks until the action is complete, unless the container process fails, in which case the handler is aborted.
    """ # noqa: E501
    post_start: Optional[IoK8sApiCoreV1LifecycleHandler] = Field(default=None, description="PostStart is called immediately after a container is created. If the handler fails, the container is terminated and restarted according to its restart policy. Other management of the container blocks until the hook completes. More info: https://kubernetes.io/docs/concepts/containers/container-lifecycle-hooks/#container-hooks", alias="postStart")
    pre_stop: Optional[IoK8sApiCoreV1LifecycleHandler] = Field(default=None, description="PreStop is called immediately before a container is terminated due to an API request or management event such as liveness/startup probe failure, preemption, resource contention, etc. The handler is not called if the container crashes or exits. The Pod's termination grace period countdown begins before the PreStop hook is executed. Regardless of the outcome of the handler, the container will eventually terminate within the Pod's termination grace period (unless delayed by finalizers). Other management of the container blocks until the hook completes or until the termination grace period is reached. More info: https://kubernetes.io/docs/concepts/containers/container-lifecycle-hooks/#container-hooks", alias="preStop")
    stop_signal: Optional[StrictStr] = Field(default=None, description="StopSignal defines which signal will be sent to a container when it is being stopped. If not specified, the default is defined by the container runtime in use. StopSignal can only be set for Pods with a non-empty .spec.os.name  Possible enum values:  - `\"SIGABRT\"`  - `\"SIGALRM\"`  - `\"SIGBUS\"`  - `\"SIGCHLD\"`  - `\"SIGCLD\"`  - `\"SIGCONT\"`  - `\"SIGFPE\"`  - `\"SIGHUP\"`  - `\"SIGILL\"`  - `\"SIGINT\"`  - `\"SIGIO\"`  - `\"SIGIOT\"`  - `\"SIGKILL\"`  - `\"SIGPIPE\"`  - `\"SIGPOLL\"`  - `\"SIGPROF\"`  - `\"SIGPWR\"`  - `\"SIGQUIT\"`  - `\"SIGRTMAX\"`  - `\"SIGRTMAX-1\"`  - `\"SIGRTMAX-10\"`  - `\"SIGRTMAX-11\"`  - `\"SIGRTMAX-12\"`  - `\"SIGRTMAX-13\"`  - `\"SIGRTMAX-14\"`  - `\"SIGRTMAX-2\"`  - `\"SIGRTMAX-3\"`  - `\"SIGRTMAX-4\"`  - `\"SIGRTMAX-5\"`  - `\"SIGRTMAX-6\"`  - `\"SIGRTMAX-7\"`  - `\"SIGRTMAX-8\"`  - `\"SIGRTMAX-9\"`  - `\"SIGRTMIN\"`  - `\"SIGRTMIN+1\"`  - `\"SIGRTMIN+10\"`  - `\"SIGRTMIN+11\"`  - `\"SIGRTMIN+12\"`  - `\"SIGRTMIN+13\"`  - `\"SIGRTMIN+14\"`  - `\"SIGRTMIN+15\"`  - `\"SIGRTMIN+2\"`  - `\"SIGRTMIN+3\"`  - `\"SIGRTMIN+4\"`  - `\"SIGRTMIN+5\"`  - `\"SIGRTMIN+6\"`  - `\"SIGRTMIN+7\"`  - `\"SIGRTMIN+8\"`  - `\"SIGRTMIN+9\"`  - `\"SIGSEGV\"`  - `\"SIGSTKFLT\"`  - `\"SIGSTOP\"`  - `\"SIGSYS\"`  - `\"SIGTERM\"`  - `\"SIGTRAP\"`  - `\"SIGTSTP\"`  - `\"SIGTTIN\"`  - `\"SIGTTOU\"`  - `\"SIGURG\"`  - `\"SIGUSR1\"`  - `\"SIGUSR2\"`  - `\"SIGVTALRM\"`  - `\"SIGWINCH\"`  - `\"SIGXCPU\"`  - `\"SIGXFSZ\"`", alias="stopSignal")
    __properties: ClassVar[List[str]] = ["postStart", "preStop", "stopSignal"]

    @field_validator('stop_signal')
    def stop_signal_validate_enum(cls, value):
        """Validates the enum"""
        if value is None:
            return value

        if value not in set(['SIGABRT', 'SIGALRM', 'SIGBUS', 'SIGCHLD', 'SIGCLD', 'SIGCONT', 'SIGFPE', 'SIGHUP', 'SIGILL', 'SIGINT', 'SIGIO', 'SIGIOT', 'SIGKILL', 'SIGPIPE', 'SIGPOLL', 'SIGPROF', 'SIGPWR', 'SIGQUIT', 'SIGRTMAX', 'SIGRTMAX-1', 'SIGRTMAX-10', 'SIGRTMAX-11', 'SIGRTMAX-12', 'SIGRTMAX-13', 'SIGRTMAX-14', 'SIGRTMAX-2', 'SIGRTMAX-3', 'SIGRTMAX-4', 'SIGRTMAX-5', 'SIGRTMAX-6', 'SIGRTMAX-7', 'SIGRTMAX-8', 'SIGRTMAX-9', 'SIGRTMIN', 'SIGRTMIN+1', 'SIGRTMIN+10', 'SIGRTMIN+11', 'SIGRTMIN+12', 'SIGRTMIN+13', 'SIGRTMIN+14', 'SIGRTMIN+15', 'SIGRTMIN+2', 'SIGRTMIN+3', 'SIGRTMIN+4', 'SIGRTMIN+5', 'SIGRTMIN+6', 'SIGRTMIN+7', 'SIGRTMIN+8', 'SIGRTMIN+9', 'SIGSEGV', 'SIGSTKFLT', 'SIGSTOP', 'SIGSYS', 'SIGTERM', 'SIGTRAP', 'SIGTSTP', 'SIGTTIN', 'SIGTTOU', 'SIGURG', 'SIGUSR1', 'SIGUSR2', 'SIGVTALRM', 'SIGWINCH', 'SIGXCPU', 'SIGXFSZ']):
            raise ValueError("must be one of enum values ('SIGABRT', 'SIGALRM', 'SIGBUS', 'SIGCHLD', 'SIGCLD', 'SIGCONT', 'SIGFPE', 'SIGHUP', 'SIGILL', 'SIGINT', 'SIGIO', 'SIGIOT', 'SIGKILL', 'SIGPIPE', 'SIGPOLL', 'SIGPROF', 'SIGPWR', 'SIGQUIT', 'SIGRTMAX', 'SIGRTMAX-1', 'SIGRTMAX-10', 'SIGRTMAX-11', 'SIGRTMAX-12', 'SIGRTMAX-13', 'SIGRTMAX-14', 'SIGRTMAX-2', 'SIGRTMAX-3', 'SIGRTMAX-4', 'SIGRTMAX-5', 'SIGRTMAX-6', 'SIGRTMAX-7', 'SIGRTMAX-8', 'SIGRTMAX-9', 'SIGRTMIN', 'SIGRTMIN+1', 'SIGRTMIN+10', 'SIGRTMIN+11', 'SIGRTMIN+12', 'SIGRTMIN+13', 'SIGRTMIN+14', 'SIGRTMIN+15', 'SIGRTMIN+2', 'SIGRTMIN+3', 'SIGRTMIN+4', 'SIGRTMIN+5', 'SIGRTMIN+6', 'SIGRTMIN+7', 'SIGRTMIN+8', 'SIGRTMIN+9', 'SIGSEGV', 'SIGSTKFLT', 'SIGSTOP', 'SIGSYS', 'SIGTERM', 'SIGTRAP', 'SIGTSTP', 'SIGTTIN', 'SIGTTOU', 'SIGURG', 'SIGUSR1', 'SIGUSR2', 'SIGVTALRM', 'SIGWINCH', 'SIGXCPU', 'SIGXFSZ')")
        return value

    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 IoK8sApiCoreV1Lifecycle 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 post_start
        if self.post_start:
            _dict['postStart'] = self.post_start.to_dict()
        # override the default output from pydantic by calling `to_dict()` of pre_stop
        if self.pre_stop:
            _dict['preStop'] = self.pre_stop.to_dict()
        return _dict

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

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

        _obj = cls.model_validate({
            "postStart": IoK8sApiCoreV1LifecycleHandler.from_dict(obj["postStart"]) if obj.get("postStart") is not None else None,
            "preStop": IoK8sApiCoreV1LifecycleHandler.from_dict(obj["preStop"]) if obj.get("preStop") is not None else None,
            "stopSignal": obj.get("stopSignal")
        })
        return _obj


