# coding: utf-8

"""
    BeeL Public API

    Public invoicing API for self-employed professionals in Spain with full VeriFactu support.  **Authentication:** This API uses **API Keys** for authentication. Endpoints are designed for external integrations, automation, and programmatic access.  For browser-based authentication, use the Private API (with Session Cookies).  **Key Features:** - VeriFactu regulatory compliance - Complete invoice management (standard, corrective, simplified) - Customer management - Tax and invoice series configuration - PDF generation - Email sending - Duplicate prevention (idempotency)  **Idempotency:** Creation endpoints (POST) support the `Idempotency-Key` header to prevent duplicates in case of retries.  **Identifiers:** - All resources use UUIDs for technical identification - Invoice numbers are human-readable and searchable 

    The version of the OpenAPI document: 1.0.0
    Contact: it@beel.es
    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 VeriFactu(BaseModel):
    """
    VeriFactu compliance information (optional). Some self-employed workers may be required to use this AEAT system, while others may choose not to. 
    """ # noqa: E501
    enabled: Optional[StrictBool] = Field(default=False, description="Whether VeriFactu is enabled for this invoice")
    invoice_hash: Optional[StrictStr] = Field(default=None, description="Invoice SHA-256 hash according to VeriFactu regulations")
    chaining_hash: Optional[StrictStr] = Field(default=None, description="Chaining hash with previous invoice")
    registration_number: Optional[StrictStr] = Field(default=None, description="Registration number in the VeriFactu system")
    qr_url: Optional[StrictStr] = Field(default=None, description="QR code URL for verification")
    qr_base64: Optional[StrictStr] = Field(default=None, description="QR code as base64-encoded PNG for embedding in custom PDFs. Only present when submission_status = ACCEPTED. ")
    registration_date: Optional[datetime] = Field(default=None, description="VeriFactu registration date and time")
    submission_status: Optional[StrictStr] = Field(default=None, description="Submission status to AEAT")
    error_code: Optional[StrictStr] = Field(default=None, description="Error code returned by AEAT. Present when submission_status is REJECTED.")
    error_message: Optional[StrictStr] = Field(default=None, description="Human-readable error description returned by AEAT. Present when submission_status is REJECTED.")
    __properties: ClassVar[List[str]] = ["enabled", "invoice_hash", "chaining_hash", "registration_number", "qr_url", "qr_base64", "registration_date", "submission_status", "error_code", "error_message"]

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

        if value not in set(['PENDING', 'SENT', 'ACCEPTED', 'VOIDED', 'REJECTED']):
            raise ValueError("must be one of enum values ('PENDING', 'SENT', 'ACCEPTED', 'VOIDED', 'REJECTED')")
        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 VeriFactu 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 qr_base64 (nullable) is None
        # and model_fields_set contains the field
        if self.qr_base64 is None and "qr_base64" in self.model_fields_set:
            _dict['qr_base64'] = None

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

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

        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of VeriFactu from a dict"""
        if obj is None:
            return None

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

        _obj = cls.model_validate({
            "enabled": obj.get("enabled") if obj.get("enabled") is not None else False,
            "invoice_hash": obj.get("invoice_hash"),
            "chaining_hash": obj.get("chaining_hash"),
            "registration_number": obj.get("registration_number"),
            "qr_url": obj.get("qr_url"),
            "qr_base64": obj.get("qr_base64"),
            "registration_date": obj.get("registration_date"),
            "submission_status": obj.get("submission_status"),
            "error_code": obj.get("error_code"),
            "error_message": obj.get("error_message")
        })
        return _obj


