# 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 datetime
from pydantic import BaseModel, ConfigDict, Field, 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 Task(BaseModel):
    """
    Task
    """ # noqa: E501
    category: Optional[StrictStr] = null
    category_custom: Optional[StrictStr] = Field(default='null', description="The name of your custom category. Can only have a value if \"category\" is \"CUSTOM\".")
    created_at: Optional[datetime] = None
    customer_id: Optional[StrictInt] = None
    description: Optional[StrictStr] = 'null'
    document_id: Optional[StrictInt] = None
    end_at: Optional[datetime] = Field(default=None, description="The deadline")
    finish_at: Optional[datetime] = Field(default=None, description="The time when the task was marked as done")
    id: Optional[StrictInt] = None
    login_id: Optional[StrictInt] = Field(default=None, description="When omitted or null, the currently active login is used")
    name: StrictStr
    position_id: Optional[StrictInt] = None
    priority: Optional[StrictStr] = 'NORMAL'
    project_id: Optional[StrictInt] = None
    start_at: Optional[datetime] = None
    status: StrictStr
    status_percent: Optional[StrictInt] = None
    __properties: ClassVar[List[str]] = ["category", "category_custom", "created_at", "customer_id", "description", "document_id", "end_at", "finish_at", "id", "login_id", "name", "position_id", "priority", "project_id", "start_at", "status", "status_percent"]

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

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

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

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

    @field_validator('status')
    def status_validate_enum(cls, value):
        """Validates the enum"""
        if value not in set(['WAITING', 'PROCESSING', 'DONE', 'CANCEL']):
            raise ValueError("must be one of enum values ('WAITING', 'PROCESSING', 'DONE', 'CANCEL')")
        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 Task 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.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        """
        excluded_fields: Set[str] = set([
            "created_at",
            "finish_at",
            "id",
        ])

        _dict = self.model_dump(
            by_alias=True,
            exclude=excluded_fields,
            exclude_none=True,
        )
        # set to None if category (nullable) is None
        # and model_fields_set contains the field
        if self.category is None and "category" in self.model_fields_set:
            _dict['category'] = None

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

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

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

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

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

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

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

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

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

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

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

        return _dict

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

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

        _obj = cls.model_validate({
            "category": obj.get("category") if obj.get("category") is not None else null,
            "category_custom": obj.get("category_custom") if obj.get("category_custom") is not None else 'null',
            "created_at": obj.get("created_at"),
            "customer_id": obj.get("customer_id"),
            "description": obj.get("description") if obj.get("description") is not None else 'null',
            "document_id": obj.get("document_id"),
            "end_at": obj.get("end_at"),
            "finish_at": obj.get("finish_at"),
            "id": obj.get("id"),
            "login_id": obj.get("login_id"),
            "name": obj.get("name"),
            "position_id": obj.get("position_id"),
            "priority": obj.get("priority") if obj.get("priority") is not None else 'NORMAL',
            "project_id": obj.get("project_id"),
            "start_at": obj.get("start_at"),
            "status": obj.get("status"),
            "status_percent": obj.get("status_percent")
        })
        return _obj


