# coding: utf-8

"""
Earnix Elevate Import Export API

No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)

The version of the OpenAPI document: 0.0.1
Generated by OpenAPI Generator (https://openapi-generator.tech)

Do not edit the class manually.
"""

from __future__ import annotations

import json
import pprint
import re
from typing import Optional

from pydantic.v1 import Field, constr, validator

from earnix_elevate.clients.imx.models.data_target_response import DataTargetResponse
from earnix_elevate.clients.imx.models.user import User


class PriceItDataTargetResponse(DataTargetResponse):
    """
    `PriceItDataTargetResponse`

    Response for an PriceIt Target that provides access to PriceIt table distanation.
    """

    project_path: Optional[constr(strict=True, max_length=500, min_length=3)] = Field(
        default=None,
        alias="projectPath",
        description="The project path within PriceIt where the data will be exported",
    )
    table_path: Optional[constr(strict=True, max_length=500, min_length=3)] = Field(
        default=None,
        alias="tablePath",
        description="The table path within PriceIt where the data will be exported",
    )
    table_name: Optional[constr(strict=True, max_length=1000, min_length=3)] = Field(
        default=None,
        alias="tableName",
        description="The table name within PriceIt where the data will be exported",
    )
    __properties = [
        "id",
        "lockVersion",
        "connectionId",
        "name",
        "description",
        "tags",
        "createdBy",
        "createdDate",
        "lastModifiedBy",
        "lastModifiedDate",
        "type",
        "connectionName",
        "projectPath",
        "tablePath",
        "tableName",
    ]

    @validator("project_path")
    def project_path_validate_regular_expression(cls, value):
        """Validates the regular expression"""
        if value is None:
            return value

        if not re.match(r"^[A-Za-z0-9\/*+= _&$()%\-\.,<>≤≥\\]*$", value):
            raise ValueError(
                r"must validate the regular expression /^[A-Za-z0-9\/*+= _&$()%\-\.,<>≤≥\\]*$/"
            )
        return value

    @validator("table_path")
    def table_path_validate_regular_expression(cls, value):
        """Validates the regular expression"""
        if value is None:
            return value

        if not re.match(r"^[A-Za-z0-9\/*+= _&$()%\-\.,<>≤≥\\]*$", value):
            raise ValueError(
                r"must validate the regular expression /^[A-Za-z0-9\/*+= _&$()%\-\.,<>≤≥\\]*$/"
            )
        return value

    @validator("table_name")
    def table_name_validate_regular_expression(cls, value):
        """Validates the regular expression"""
        if value is None:
            return value

        if not re.match(r"^[A-Za-z0-9\/*+= _&$()%\-\.,<>≤≥{}]*$", value):
            raise ValueError(
                r"must validate the regular expression /^[A-Za-z0-9\/*+= _&$()%\-\.,<>≤≥{}]*$/"
            )
        return value

    class Config:
        """Pydantic configuration"""

        allow_population_by_field_name = True
        validate_assignment = True

    def to_str(self) -> str:
        """Returns the string representation of the model using alias"""
        return pprint.pformat(self.dict(by_alias=True))

    def to_json(self) -> str:
        """Returns the JSON representation of the model using alias"""
        return json.dumps(self.to_dict())

    @classmethod
    def from_json(cls, json_str: str) -> PriceItDataTargetResponse:
        """Create an instance of PriceItDataTargetResponse from a JSON string"""
        return cls.from_dict(json.loads(json_str))

    def to_dict(self):
        """Returns the dictionary representation of the model using alias"""
        _dict = self.dict(by_alias=True, exclude={}, exclude_none=True)
        # override the default output from pydantic by calling `to_dict()` of created_by
        if self.created_by:
            _dict["createdBy"] = self.created_by.to_dict()
        # override the default output from pydantic by calling `to_dict()` of last_modified_by
        if self.last_modified_by:
            _dict["lastModifiedBy"] = self.last_modified_by.to_dict()
        # set to None if description (nullable) is None
        # and __fields_set__ contains the field
        if self.description is None and "description" in self.__fields_set__:
            _dict["description"] = None

        return _dict

    @classmethod
    def from_dict(cls, obj: dict) -> PriceItDataTargetResponse:
        """Create an instance of PriceItDataTargetResponse from a dict"""
        if obj is None:
            return None

        if not isinstance(obj, dict):
            return PriceItDataTargetResponse.parse_obj(obj)

        _obj = PriceItDataTargetResponse.parse_obj(
            {
                "id": obj.get("id"),
                "lock_version": obj.get("lockVersion"),
                "connection_id": obj.get("connectionId"),
                "name": obj.get("name"),
                "description": obj.get("description"),
                "tags": obj.get("tags"),
                "created_by": User.from_dict(obj.get("createdBy"))
                if obj.get("createdBy") is not None
                else None,
                "created_date": obj.get("createdDate"),
                "last_modified_by": User.from_dict(obj.get("lastModifiedBy"))
                if obj.get("lastModifiedBy") is not None
                else None,
                "last_modified_date": obj.get("lastModifiedDate"),
                "type": obj.get("type"),
                "connection_name": obj.get("connectionName"),
                "project_path": obj.get("projectPath"),
                "table_path": obj.get("tablePath"),
                "table_name": obj.get("tableName"),
            }
        )
        return _obj
