# 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, StrictStr, field_validator
from typing import Any, ClassVar, Dict, List, Optional
from voucherify.models.export_parameters import ExportParameters
from voucherify.models.export_result import ExportResult
from typing import Optional, Set
from typing_extensions import Self

class Export(BaseModel):
    """
    Export
    """ # noqa: E501
    id: Optional[StrictStr] = Field(default=None, description="Unique export ID.")
    object: Optional[StrictStr] = Field(default='export', description="The type of object being represented. This object stores information about the export.")
    created_at: Optional[datetime] = Field(default=None, description="Timestamp representing the date and time when the export was scheduled in ISO 8601 format.")
    status: Optional[StrictStr] = Field(default=None, description="Status of the export. Informs you whether the export has already been completed, i.e. indicates whether the file containing the exported data has been generated.")
    channel: Optional[StrictStr] = Field(default=None, description="The channel through which the export was triggered.")
    result: Optional[ExportResult] = None
    user_id: Optional[StrictStr] = Field(default=None, description="Identifies the specific user who initiated the export through the Voucherify Dashboard; returned when the channel value is WEBSITE.")
    exported_object: Optional[StrictStr] = None
    parameters: Optional[ExportParameters] = None
    __properties: ClassVar[List[str]] = ["id", "object", "created_at", "status", "channel", "result", "user_id", "exported_object", "parameters"]

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

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

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

        if value not in set(['SCHEDULED', 'IN_PROGRESS', 'DONE', 'ERROR']):
            raise ValueError("must be one of enum values ('SCHEDULED', 'IN_PROGRESS', 'DONE', 'ERROR')")
        return value

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

        if value not in set(['voucher', 'redemption', 'customer', 'publication', 'order', 'points_expiration', 'voucher_transactions']):
            raise ValueError("must be one of enum values ('voucher', 'redemption', 'customer', 'publication', 'order', 'points_expiration', 'voucher_transactions')")
        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 Export 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,
        )
        # override the default output from pydantic by calling `to_dict()` of result
        if self.result:
            _dict['result'] = self.result.to_dict()
        # override the default output from pydantic by calling `to_dict()` of parameters
        if self.parameters:
            _dict['parameters'] = self.parameters.to_dict()
        # 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 status (nullable) is None
        # and model_fields_set contains the field
        if self.status is None and "status" in self.model_fields_set:
            _dict['status'] = None

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

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

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

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

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

        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of Export 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 'export',
            "created_at": obj.get("created_at"),
            "status": obj.get("status"),
            "channel": obj.get("channel"),
            "result": ExportResult.from_dict(obj["result"]) if obj.get("result") is not None else None,
            "user_id": obj.get("user_id"),
            "exported_object": obj.get("exported_object"),
            "parameters": ExportParameters.from_dict(obj["parameters"]) if obj.get("parameters") is not None else None
        })
        return _obj


