# coding: utf-8

"""
    authentik

    Making authentication simple.

    The version of the OpenAPI document: 2026.2.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 date
from pydantic import BaseModel, ConfigDict, StrictBool, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List
from uuid import UUID
from authentik_client.models.content_type_enum import ContentTypeEnum
from authentik_client.models.lifecycle_iteration_state_enum import LifecycleIterationStateEnum
from authentik_client.models.review import Review
from authentik_client.models.reviewer_group import ReviewerGroup
from authentik_client.models.reviewer_user import ReviewerUser
from typing import Optional, Set
from typing_extensions import Self

class LifecycleIteration(BaseModel):
    """
    Mixin to validate that a valid enterprise license exists before allowing to save the object
    """ # noqa: E501
    id: UUID
    content_type: ContentTypeEnum
    object_id: StrictStr
    object_verbose: StrictStr
    object_admin_url: StrictStr
    state: LifecycleIterationStateEnum
    opened_on: date
    grace_period_end: date
    next_review_date: date
    reviews: List[Review]
    user_can_review: StrictBool
    reviewer_groups: List[ReviewerGroup]
    min_reviewers: StrictInt
    reviewers: List[ReviewerUser]
    __properties: ClassVar[List[str]] = ["id", "content_type", "object_id", "object_verbose", "object_admin_url", "state", "opened_on", "grace_period_end", "next_review_date", "reviews", "user_can_review", "reviewer_groups", "min_reviewers", "reviewers"]

    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 LifecycleIteration 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.
        * 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",
            "object_id",
            "object_verbose",
            "object_admin_url",
            "state",
            "opened_on",
            "grace_period_end",
            "next_review_date",
            "reviews",
            "user_can_review",
            "reviewer_groups",
            "min_reviewers",
            "reviewers",
        ])

        _dict = self.model_dump(
            by_alias=True,
            exclude=excluded_fields,
            exclude_none=True,
        )
        # override the default output from pydantic by calling `to_dict()` of each item in reviews (list)
        _items = []
        if self.reviews:
            for _item_reviews in self.reviews:
                if _item_reviews:
                    _items.append(_item_reviews.to_dict())
            _dict['reviews'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in reviewer_groups (list)
        _items = []
        if self.reviewer_groups:
            for _item_reviewer_groups in self.reviewer_groups:
                if _item_reviewer_groups:
                    _items.append(_item_reviewer_groups.to_dict())
            _dict['reviewer_groups'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in reviewers (list)
        _items = []
        if self.reviewers:
            for _item_reviewers in self.reviewers:
                if _item_reviewers:
                    _items.append(_item_reviewers.to_dict())
            _dict['reviewers'] = _items
        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of LifecycleIteration 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"),
            "content_type": obj.get("content_type"),
            "object_id": obj.get("object_id"),
            "object_verbose": obj.get("object_verbose"),
            "object_admin_url": obj.get("object_admin_url"),
            "state": obj.get("state"),
            "opened_on": obj.get("opened_on"),
            "grace_period_end": obj.get("grace_period_end"),
            "next_review_date": obj.get("next_review_date"),
            "reviews": [Review.from_dict(_item) for _item in obj["reviews"]] if obj.get("reviews") is not None else None,
            "user_can_review": obj.get("user_can_review"),
            "reviewer_groups": [ReviewerGroup.from_dict(_item) for _item in obj["reviewer_groups"]] if obj.get("reviewer_groups") is not None else None,
            "min_reviewers": obj.get("min_reviewers"),
            "reviewers": [ReviewerUser.from_dict(_item) for _item in obj["reviewers"]] if obj.get("reviewers") is not None else None
        })
        return _obj


