# coding: utf-8

"""
    Voucherify API

    Voucherify promotion engine REST API. Please see https://docs.voucherify.io/docs for more details.

    The version of the OpenAPI document: v2018-08-01
    Contact: support@voucherify.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, field_validator
from typing import Any, ClassVar, Dict, List, Optional
from typing import Optional, Set
from typing_extensions import Self

class ManagementProjectsWebhooksUpdateResponseBody(BaseModel):
    """
    Response body schema for **PUT** `/management/v1/projects/{projectId}/webhooks/{webhookId}`.
    """ # noqa: E501
    id: Optional[StrictStr] = Field(default=None, description="Unique identifier of the webhook.")
    object: Optional[StrictStr] = Field(default='webhook', description="The type of the object represented by JSON.")
    created_at: Optional[datetime] = Field(default=None, description="Timestamp representing the date and time when the webhook configuration was created. The value for this parameter is shown in the ISO 8601 format.")
    target_url: Optional[StrictStr] = Field(default=None, description="URL address that receives webhooks.")
    events: Optional[List[StrictStr]] = Field(default=None, description="Lists the events that trigger webhook sendout.")
    active: Optional[StrictBool] = Field(default=True, description="Determines if the webhook configuration is active.")
    __properties: ClassVar[List[str]] = ["id", "object", "created_at", "target_url", "events", "active"]

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

        if value not in set(['webhook']):
            raise ValueError("must be one of enum values ('webhook')")
        return value

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

        for i in value:
            if i not in set(['business_validation_rule.assignment.created', 'business_validation_rule.assignment.deleted', 'business_validation_rule.created', 'business_validation_rule.deleted', 'business_validation_rule.updated', 'campaign.created', 'campaign.deleted', 'campaign.disabled', 'campaign.enabled', 'campaign.earning_rule.assigned', 'campaign.earning_rule.deleted', 'campaign.earning_rule.disabled', 'campaign.earning_rule.enabled', 'campaign.earning_rule.updated', 'campaign.loyalty_tier.created', 'campaign.loyalty_tier.deleted', 'campaign.loyalty_tier.updated', 'campaign.promotion_stack.created', 'campaign.promotion_stack.updated', 'campaign.promotion_tier.created', 'campaign.promotion_tier.deleted', 'campaign.promotion_tier.disabled', 'campaign.promotion_tier.enabled', 'campaign.promotion_tier.updated', 'campaign.referral_tier.created', 'campaign.referral_tier.deleted', 'campaign.referral_tier.updated', 'campaign.reward.assignment.created', 'campaign.reward.assignment.deleted', 'campaign.reward.assignment.updated', 'campaign.updated', 'campaign.vouchers.aded', 'campaign.vouchers.generation.completed', 'campaign.vouchers.generation.failed', 'campaign.vouchers.generation.started', 'customer.confirmed', 'customer.created', 'customer.deleted', 'customer.rewarded', 'customer.rewarded.loyalty_points', 'publication.succeeded', 'redemption.failed', 'redemption.rollback.failed', 'redemption.rollback.succeeded', 'redemption.succeeded', 'voucher.created', 'voucher.deleted', 'voucher.disabled', 'voucher.enabled', 'voucher.gift.balance_aded', 'voucher.gift.transaction.created', 'voucher.loyalty_card.pending_points.activated', 'voucher.loyalty_card.pending_points.aded', 'voucher.loyalty_card.pending_points.canceled', 'voucher.loyalty_card.pending_points.updated', 'voucher.loyalty_card.points_aded', 'voucher.loyalty_card.points_expired', 'voucher.loyalty_card.transaction.created', 'voucher.published', 'voucher.updated']):
                raise ValueError("each list item must be one of ('business_validation_rule.assignment.created', 'business_validation_rule.assignment.deleted', 'business_validation_rule.created', 'business_validation_rule.deleted', 'business_validation_rule.updated', 'campaign.created', 'campaign.deleted', 'campaign.disabled', 'campaign.enabled', 'campaign.earning_rule.assigned', 'campaign.earning_rule.deleted', 'campaign.earning_rule.disabled', 'campaign.earning_rule.enabled', 'campaign.earning_rule.updated', 'campaign.loyalty_tier.created', 'campaign.loyalty_tier.deleted', 'campaign.loyalty_tier.updated', 'campaign.promotion_stack.created', 'campaign.promotion_stack.updated', 'campaign.promotion_tier.created', 'campaign.promotion_tier.deleted', 'campaign.promotion_tier.disabled', 'campaign.promotion_tier.enabled', 'campaign.promotion_tier.updated', 'campaign.referral_tier.created', 'campaign.referral_tier.deleted', 'campaign.referral_tier.updated', 'campaign.reward.assignment.created', 'campaign.reward.assignment.deleted', 'campaign.reward.assignment.updated', 'campaign.updated', 'campaign.vouchers.aded', 'campaign.vouchers.generation.completed', 'campaign.vouchers.generation.failed', 'campaign.vouchers.generation.started', 'customer.confirmed', 'customer.created', 'customer.deleted', 'customer.rewarded', 'customer.rewarded.loyalty_points', 'publication.succeeded', 'redemption.failed', 'redemption.rollback.failed', 'redemption.rollback.succeeded', 'redemption.succeeded', 'voucher.created', 'voucher.deleted', 'voucher.disabled', 'voucher.enabled', 'voucher.gift.balance_aded', 'voucher.gift.transaction.created', 'voucher.loyalty_card.pending_points.activated', 'voucher.loyalty_card.pending_points.aded', 'voucher.loyalty_card.pending_points.canceled', 'voucher.loyalty_card.pending_points.updated', 'voucher.loyalty_card.points_aded', 'voucher.loyalty_card.points_expired', 'voucher.loyalty_card.transaction.created', 'voucher.published', 'voucher.updated')")
        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 ManagementProjectsWebhooksUpdateResponseBody 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,
        )
        # set to None if id (nullable) is None
        # and model_fields_set contains the field
        if self.id is None and "id" in self.model_fields_set:
            _dict['id'] = None

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

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

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

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

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

        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of ManagementProjectsWebhooksUpdateResponseBody 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"),
            "object": obj.get("object") if obj.get("object") is not None else 'webhook',
            "created_at": obj.get("created_at"),
            "target_url": obj.get("target_url"),
            "events": obj.get("events"),
            "active": obj.get("active") if obj.get("active") is not None else True
        })
        return _obj


