# coding: utf-8

"""
    DeviceServer

    DeviceServer API

    The version of the OpenAPI document: 1.2.2
    Contact: david@3adesign.co.uk
    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, field_validator
from typing import Any, ClassVar, Dict, List, Optional
from typing_extensions import Annotated
from typing import Optional, Set
from typing_extensions import Self

class Device(BaseModel):
    """
    Model representing a device, used for both API interactions and database storage. This model includes attributes such as device ID, index, name, type, and various counts (ports, buttons, LEDs), as well as a serial number. 
    """ # noqa: E501
    device_id: Annotated[str, Field(min_length=36, strict=True, max_length=36)]
    device_index: Annotated[int, Field(strict=True, ge=0)]
    device_type: Optional[Annotated[str, Field(min_length=1, strict=True, max_length=100)]] = None
    device_serial: Optional[Annotated[str, Field(min_length=1, strict=True, max_length=32)]] = None
    name: Annotated[str, Field(min_length=1, strict=True, max_length=64)]
    description: Optional[Annotated[str, Field(strict=True, max_length=100)]] = None
    port_count: Optional[Annotated[int, Field(le=1000, strict=True, ge=0)]] = Field(default=None, description="Number of ports available on device")
    button_count: Optional[Annotated[int, Field(le=1000, strict=True, ge=0)]] = Field(default=None, description="Number of buttons available on device")
    led_count: Optional[Annotated[int, Field(le=1000, strict=True, ge=0)]] = Field(default=None, description="Number of leds available on device")
    temperature_port_count: Optional[Annotated[int, Field(le=1000, strict=True, ge=0)]] = Field(default=None, description="Number of temperature ports available on device")
    __properties: ClassVar[List[str]] = ["device_id", "device_index", "device_type", "device_serial", "name", "description", "port_count", "button_count", "led_count", "temperature_port_count"]

    @field_validator('device_id')
    def device_id_validate_regular_expression(cls, value):
        """Validates the regular expression"""
        if not re.match(r"[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}", value):
            raise ValueError(r"must validate the regular expression /[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}/")
        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 Device 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,
        )
        return _dict

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

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

        _obj = cls.model_validate({
            "device_id": obj.get("device_id"),
            "device_index": obj.get("device_index"),
            "device_type": obj.get("device_type"),
            "device_serial": obj.get("device_serial"),
            "name": obj.get("name"),
            "description": obj.get("description"),
            "port_count": obj.get("port_count"),
            "button_count": obj.get("button_count"),
            "led_count": obj.get("led_count"),
            "temperature_port_count": obj.get("temperature_port_count")
        })
        return _obj


