# coding: utf-8

"""
    Identity Security Cloud Beta API

    Use these APIs to interact with the Identity Security Cloud platform to achieve repeatable, automated processes with greater scalability. These APIs are in beta and are subject to change. We encourage you to join the SailPoint Developer Community forum at https://developer.sailpoint.com/discuss to connect with other developers using our APIs.

    The version of the OpenAPI document: 3.1.0-beta
    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 Any, ClassVar, Dict, List, Optional
from pydantic import BaseModel, StrictBool, StrictInt, StrictStr, field_validator
from pydantic import Field
from sailpoint.beta.models.form_instance_created_by import FormInstanceCreatedBy
from sailpoint.beta.models.form_instance_recipient import FormInstanceRecipient
try:
    from typing import Self
except ImportError:
    from typing_extensions import Self

class CreateFormInstanceRequest(BaseModel):
    """
    CreateFormInstanceRequest
    """ # noqa: E501
    created_by: FormInstanceCreatedBy = Field(alias="createdBy")
    expire: StrictStr = Field(description="Expire is required")
    form_definition_id: StrictStr = Field(description="FormDefinitionID is the id of the form definition that created this form", alias="formDefinitionId")
    form_input: Optional[Dict[str, Any]] = Field(default=None, description="FormInput is an object of form input labels to value", alias="formInput")
    recipients: List[FormInstanceRecipient] = Field(description="Recipients is required")
    stand_alone_form: Optional[StrictBool] = Field(default=False, description="StandAloneForm is a boolean flag to indicate if this form should be available for users to complete via the standalone form UI or should this only be available to be completed by as an embedded form", alias="standAloneForm")
    state: Optional[StrictStr] = Field(default=None, description="State is required, if not present initial state is FormInstanceStateAssigned ASSIGNED FormInstanceStateAssigned IN_PROGRESS FormInstanceStateInProgress SUBMITTED FormInstanceStateSubmitted COMPLETED FormInstanceStateCompleted CANCELLED FormInstanceStateCancelled")
    ttl: Optional[StrictInt] = Field(default=None, description="TTL an epoch timestamp in seconds, it most be in seconds or dynamodb will ignore it SEE: https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/time-to-live-ttl-before-you-start.html")
    __properties: ClassVar[List[str]] = ["createdBy", "expire", "formDefinitionId", "formInput", "recipients", "standAloneForm", "state", "ttl"]

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

        if value not in ('ASSIGNED', 'IN_PROGRESS', 'SUBMITTED', 'COMPLETED', 'CANCELLED'):
            raise ValueError("must be one of enum values ('ASSIGNED', 'IN_PROGRESS', 'SUBMITTED', 'COMPLETED', 'CANCELLED')")
        return value

    model_config = {
        "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) -> Self:
        """Create an instance of CreateFormInstanceRequest 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.
        """
        _dict = self.model_dump(
            by_alias=True,
            exclude={
            },
            exclude_none=True,
        )
        # override the default output from pydantic by calling `to_dict()` of created_by
        if self.created_by:
            _dict['createdBy'] = self.created_by.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in recipients (list)
        _items = []
        if self.recipients:
            for _item in self.recipients:
                if _item:
                    _items.append(_item.to_dict())
            _dict['recipients'] = _items
        return _dict

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

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

        _obj = cls.model_validate({
            "createdBy": FormInstanceCreatedBy.from_dict(obj.get("createdBy")) if obj.get("createdBy") is not None else None,
            "expire": obj.get("expire"),
            "formDefinitionId": obj.get("formDefinitionId"),
            "formInput": obj.get("formInput"),
            "recipients": [FormInstanceRecipient.from_dict(_item) for _item in obj.get("recipients")] if obj.get("recipients") is not None else None,
            "standAloneForm": obj.get("standAloneForm") if obj.get("standAloneForm") is not None else False,
            "state": obj.get("state"),
            "ttl": obj.get("ttl")
        })
        return _obj


