# 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 pydantic import BaseModel, ConfigDict, Field, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from typing_extensions import Annotated
from beel_generated.models.csv_validation_error import CsvValidationError
from beel_generated.models.customer import Customer
from typing import Optional, Set
from typing_extensions import Self

class CsvImportResult(BaseModel):
    """
    CsvImportResult
    """ # noqa: E501
    total_processed: Annotated[int, Field(strict=True, ge=0)] = Field(description="Total records processed from CSV")
    successful: Annotated[int, Field(strict=True, ge=0)] = Field(description="Number of customers successfully created")
    failed: Annotated[int, Field(strict=True, ge=0)] = Field(description="Number of records that failed")
    duplicates_skipped: Annotated[int, Field(strict=True, ge=0)] = Field(description="Number of records skipped as duplicates (same Tax ID)")
    created_customers: Optional[List[Customer]] = Field(default=None, description="List of successfully created customers")
    errors: Optional[List[CsvValidationError]] = Field(default=None, description="Error details by row")
    warnings: Optional[List[StrictStr]] = Field(default=None, description="Non-critical warnings (missing optional fields)")
    __properties: ClassVar[List[str]] = ["total_processed", "successful", "failed", "duplicates_skipped", "created_customers", "errors", "warnings"]

    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 CsvImportResult 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 each item in created_customers (list)
        _items = []
        if self.created_customers:
            for _item_created_customers in self.created_customers:
                if _item_created_customers:
                    _items.append(_item_created_customers.to_dict())
            _dict['created_customers'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in errors (list)
        _items = []
        if self.errors:
            for _item_errors in self.errors:
                if _item_errors:
                    _items.append(_item_errors.to_dict())
            _dict['errors'] = _items
        return _dict

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

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

        _obj = cls.model_validate({
            "total_processed": obj.get("total_processed"),
            "successful": obj.get("successful"),
            "failed": obj.get("failed"),
            "duplicates_skipped": obj.get("duplicates_skipped"),
            "created_customers": [Customer.from_dict(_item) for _item in obj["created_customers"]] if obj.get("created_customers") is not None else None,
            "errors": [CsvValidationError.from_dict(_item) for _item in obj["errors"]] if obj.get("errors") is not None else None,
            "warnings": obj.get("warnings")
        })
        return _obj


