# coding: utf-8

"""
    easybill REST API

     The first version of the easybill REST API. [CHANGELOG](https://api.easybill.de/rest/v1/CHANGELOG.md)  ## Authentication  You can choose between two available methods: `Basic Auth` or `Bearer Token`.  In each HTTP request, one of the following HTTP headers is required:  ``` # Basic Auth Authorization: Basic base64_encode('<email>:<api_key>') # Bearer Token Authorization: Bearer <api_key> ```  ## Limitations  ### Request Limit  * PLUS: 10 requests per minute * BUSINESS: 60 requests per minute  If the limit is exceeded, you will receive the HTTP error: `429 Too Many Requests`  ### Result Limit  All result lists are limited to 100 by default. This limit can be increased by the query parameter `limit` to a maximum of 1000.  ## Query filter  Many list resources can be filtered. In `/documents` you can filter e.g. by number with `/documents?number=111028654`. If you want to filter multiple numbers, you can either enter them separated by commas `/documents?number=111028654,222006895` or as an array `/documents?number[]=111028654&number[]=222006895`.  **Warning**: The maximum size of an HTTP request line in bytes is 4094. If this limit is exceeded, you will receive the HTTP error: `414 Request-URI Too Large`  ### Escape commas in query  You can escape commans in query `name=Patrick\\, Peter` if you submit the header `X-Easybill-Escape: true` in your request.  ## Property login_id  This is the login of your admin or employee account.  ## Date and Date-Time format Please use the timezone `Europe/Berlin`. * **date** = *Y-m-d* = `2016-12-31` * **date-time** = *Y-m-d H:i:s* = `2016-12-31 03:13:37`  Date or datetime can be `null` because the attributes have been added later and the entry is older.

    The version of the OpenAPI document: 1.96.0
    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 date
from pydantic import BaseModel, ConfigDict, Field, StrictBool, StrictInt, StrictStr, field_validator
from typing import Any, ClassVar, Dict, List, Optional
from typing import Optional, Set
from typing_extensions import Self
from pydantic_core import to_jsonable_python

class DocumentRecurring(BaseModel):
    """
    This object is only available in document type RECURRING.
    """ # noqa: E501
    next_date: date = Field(description="Must be in the future")
    frequency: Optional[StrictStr] = 'MONTHLY'
    frequency_special: Optional[StrictStr] = null
    interval: Optional[StrictInt] = None
    end_date_or_count: Optional[StrictStr] = Field(default='null', description="Date of last exectution day or number of times to exectute")
    status: Optional[StrictStr] = 'WAITING'
    as_draft: Optional[StrictBool] = False
    is_notify: Optional[StrictBool] = False
    send_as: Optional[StrictStr] = null
    is_sign: Optional[StrictBool] = False
    is_paid: Optional[StrictBool] = False
    paid_date_option: Optional[StrictStr] = Field(default='created_date', description="Option is used to determine what date is used for the payment if is_paid is true. \"next_valid_date\" selects the next workday in regards to the created date of the document if the date falls on a saturday or sunday.")
    is_sepa: Optional[StrictBool] = False
    sepa_local_instrument: Optional[StrictStr] = Field(default=null, description="COR1 is deprecated use CORE instead.")
    sepa_sequence_type: Optional[StrictStr] = null
    sepa_reference: Optional[StrictStr] = 'null'
    sepa_remittance_information: Optional[StrictStr] = 'null'
    target_type: Optional[StrictStr] = Field(default='INVOICE', description="The document type that will be generated. Can not be changed on existing documents.")
    __properties: ClassVar[List[str]] = ["next_date", "frequency", "frequency_special", "interval", "end_date_or_count", "status", "as_draft", "is_notify", "send_as", "is_sign", "is_paid", "paid_date_option", "is_sepa", "sepa_local_instrument", "sepa_sequence_type", "sepa_reference", "sepa_remittance_information", "target_type"]

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

        if value not in set(['DAILY', 'WEEKLY', 'MONTHLY', 'YEARLY']):
            raise ValueError("must be one of enum values ('DAILY', 'WEEKLY', 'MONTHLY', 'YEARLY')")
        return value

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

        if value not in set(['LASTDAYOFMONTH']):
            raise ValueError("must be one of enum values ('LASTDAYOFMONTH')")
        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(['RUNNING', 'PAUSE', 'STOP', 'WAITING']):
            raise ValueError("must be one of enum values ('RUNNING', 'PAUSE', 'STOP', 'WAITING')")
        return value

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

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

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

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

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

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

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

        if value not in set(['FRST', 'OOFF', 'FNAL', 'RCUR']):
            raise ValueError("must be one of enum values ('FRST', 'OOFF', 'FNAL', 'RCUR')")
        return value

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

        if value not in set(['INVOICE', 'CREDIT', 'ORDER', 'OFFER']):
            raise ValueError("must be one of enum values ('INVOICE', 'CREDIT', 'ORDER', 'OFFER')")
        return value

    model_config = ConfigDict(
        validate_by_name=True,
        validate_by_alias=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"""
        return json.dumps(to_jsonable_python(self.to_dict()))

    @classmethod
    def from_json(cls, json_str: str) -> Optional[Self]:
        """Create an instance of DocumentRecurring 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 frequency_special (nullable) is None
        # and model_fields_set contains the field
        if self.frequency_special is None and "frequency_special" in self.model_fields_set:
            _dict['frequency_special'] = None

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

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

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

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

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

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

        return _dict

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

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

        _obj = cls.model_validate({
            "next_date": obj.get("next_date"),
            "frequency": obj.get("frequency") if obj.get("frequency") is not None else 'MONTHLY',
            "frequency_special": obj.get("frequency_special") if obj.get("frequency_special") is not None else null,
            "interval": obj.get("interval"),
            "end_date_or_count": obj.get("end_date_or_count") if obj.get("end_date_or_count") is not None else 'null',
            "status": obj.get("status") if obj.get("status") is not None else 'WAITING',
            "as_draft": obj.get("as_draft") if obj.get("as_draft") is not None else False,
            "is_notify": obj.get("is_notify") if obj.get("is_notify") is not None else False,
            "send_as": obj.get("send_as") if obj.get("send_as") is not None else null,
            "is_sign": obj.get("is_sign") if obj.get("is_sign") is not None else False,
            "is_paid": obj.get("is_paid") if obj.get("is_paid") is not None else False,
            "paid_date_option": obj.get("paid_date_option") if obj.get("paid_date_option") is not None else 'created_date',
            "is_sepa": obj.get("is_sepa") if obj.get("is_sepa") is not None else False,
            "sepa_local_instrument": obj.get("sepa_local_instrument") if obj.get("sepa_local_instrument") is not None else null,
            "sepa_sequence_type": obj.get("sepa_sequence_type") if obj.get("sepa_sequence_type") is not None else null,
            "sepa_reference": obj.get("sepa_reference") if obj.get("sepa_reference") is not None else 'null',
            "sepa_remittance_information": obj.get("sepa_remittance_information") if obj.get("sepa_remittance_information") is not None else 'null',
            "target_type": obj.get("target_type") if obj.get("target_type") is not None else 'INVOICE'
        })
        return _obj


