# coding: utf-8

"""
    authentik

    Making authentication simple.

    The version of the OpenAPI document: 2025.10.0-rc1
    Contact: hello@goauthentik.io
    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, Field, StrictBool, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from uuid import UUID
from authentik_client.models.last_task_status_enum import LastTaskStatusEnum
from typing import Optional, Set
from typing_extensions import Self

class Schedule(BaseModel):
    """
    Schedule
    """ # noqa: E501
    id: UUID
    identifier: Optional[StrictStr] = Field(description="Unique schedule identifier")
    uid: StrictStr
    actor_name: StrictStr = Field(description="Dramatiq actor to call")
    rel_obj_app_label: StrictStr
    rel_obj_model: StrictStr
    rel_obj_id: Optional[StrictStr] = None
    crontab: StrictStr = Field(description="When to schedule tasks")
    paused: Optional[StrictBool] = Field(default=None, description="Pause this schedule")
    next_run: datetime
    description: Optional[StrictStr]
    last_task_status: Optional[LastTaskStatusEnum]
    __properties: ClassVar[List[str]] = ["id", "identifier", "uid", "actor_name", "rel_obj_app_label", "rel_obj_model", "rel_obj_id", "crontab", "paused", "next_run", "description", "last_task_status"]

    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.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        """
        excluded_fields: Set[str] = set([
            "id",
            "identifier",
            "uid",
            "actor_name",
            "rel_obj_app_label",
            "rel_obj_model",
            "next_run",
            "description",
            "last_task_status",
        ])

        _dict = self.model_dump(
            by_alias=True,
            exclude=excluded_fields,
            exclude_none=True,
        )
        # set to None if identifier (nullable) is None
        # and model_fields_set contains the field
        if self.identifier is None and "identifier" in self.model_fields_set:
            _dict['identifier'] = None

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

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

        # set to None if last_task_status (nullable) is None
        # and model_fields_set contains the field
        if self.last_task_status is None and "last_task_status" in self.model_fields_set:
            _dict['last_task_status'] = 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({
            "id": obj.get("id"),
            "identifier": obj.get("identifier"),
            "uid": obj.get("uid"),
            "actor_name": obj.get("actor_name"),
            "rel_obj_app_label": obj.get("rel_obj_app_label"),
            "rel_obj_model": obj.get("rel_obj_model"),
            "rel_obj_id": obj.get("rel_obj_id"),
            "crontab": obj.get("crontab"),
            "paused": obj.get("paused"),
            "next_run": obj.get("next_run"),
            "description": obj.get("description"),
            "last_task_status": obj.get("last_task_status")
        })
        return _obj


