# coding: utf-8

"""
    VerificationService

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

    The version of the OpenAPI document: 1.0.0
    Contact: info@affinidi.com
    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 List, Optional
from pydantic import BaseModel, StrictStr, conlist, validator
from affinidi_tdk_credential_verification_client.models.constraints_statuses import ConstraintsStatuses
from affinidi_tdk_credential_verification_client.models.field import Field
from affinidi_tdk_credential_verification_client.models.holder_subject import HolderSubject

class Constraints(BaseModel):
    """
    Constraints
    """
    limit_disclosure: Optional[StrictStr] = None
    statuses: Optional[ConstraintsStatuses] = None
    fields: Optional[conlist(Field)] = None
    subject_is_issuer: Optional[StrictStr] = None
    is_holder: Optional[conlist(HolderSubject)] = None
    same_subject: Optional[conlist(HolderSubject)] = None
    __properties = ["limit_disclosure", "statuses", "fields", "subject_is_issuer", "is_holder", "same_subject"]

    @validator('limit_disclosure')
    def limit_disclosure_validate_enum(cls, value):
        """Validates the enum"""
        if value is None:
            return value

        if value not in ('required', 'preferred',):
            raise ValueError("must be one of enum values ('required', 'preferred')")
        return value

    @validator('subject_is_issuer')
    def subject_is_issuer_validate_enum(cls, value):
        """Validates the enum"""
        if value is None:
            return value

        if value not in ('required', 'preferred',):
            raise ValueError("must be one of enum values ('required', 'preferred')")
        return value

    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) -> Constraints:
        """Create an instance of Constraints 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 statuses
        if self.statuses:
            _dict['statuses'] = self.statuses.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in fields (list)
        _items = []
        if self.fields:
            for _item in self.fields:
                if _item:
                    _items.append(_item.to_dict())
            _dict['fields'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in is_holder (list)
        _items = []
        if self.is_holder:
            for _item in self.is_holder:
                if _item:
                    _items.append(_item.to_dict())
            _dict['is_holder'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in same_subject (list)
        _items = []
        if self.same_subject:
            for _item in self.same_subject:
                if _item:
                    _items.append(_item.to_dict())
            _dict['same_subject'] = _items
        return _dict

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

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

        _obj = Constraints.parse_obj({
            "limit_disclosure": obj.get("limit_disclosure"),
            "statuses": ConstraintsStatuses.from_dict(obj.get("statuses")) if obj.get("statuses") is not None else None,
            "fields": [Field.from_dict(_item) for _item in obj.get("fields")] if obj.get("fields") is not None else None,
            "subject_is_issuer": obj.get("subject_is_issuer"),
            "is_holder": [HolderSubject.from_dict(_item) for _item in obj.get("is_holder")] if obj.get("is_holder") is not None else None,
            "same_subject": [HolderSubject.from_dict(_item) for _item in obj.get("same_subject")] if obj.get("same_subject") is not None else None
        })
        return _obj


