# 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
from typing import Optional

from pydantic.v1 import BaseModel, Field, StrictInt, constr


class UpdateConnectionTypeMappingRequest(BaseModel):
    """
    `UpdateConnectionTypeMappingRequest`

    Request to update the type mapping of a price it connection.
    """

    id: StrictInt = Field(
        default=..., description="The unique identifier of the entity"
    )
    lock_version: StrictInt = Field(
        default=...,
        alias="lockVersion",
        description="The current version of the entity used for optimistic locking to prevent concurrent modifications",
    )
    type_mapping: constr(strict=True, max_length=100000, min_length=2) = Field(
        default=...,
        alias="typeMapping",
        description='JSON-formatted string mapping source columns to target types in price-it. Keys are source column names, values are target type values in price-it. Example: {"columnA":"integer","columnB":"text"}',
    )
    type_mapping_name: Optional[constr(strict=True, max_length=100)] = Field(
        default=None,
        alias="typeMappingName",
        description="Optional name/label for the type mapping configuration.",
    )
    __properties = ["id", "lockVersion", "typeMapping", "typeMappingName"]

    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) -> UpdateConnectionTypeMappingRequest:
        """Create an instance of UpdateConnectionTypeMappingRequest 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)
        # set to None if type_mapping_name (nullable) is None
        # and __fields_set__ contains the field
        if (
            self.type_mapping_name is None
            and "type_mapping_name" in self.__fields_set__
        ):
            _dict["typeMappingName"] = None

        return _dict

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

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

        _obj = UpdateConnectionTypeMappingRequest.parse_obj(
            {
                "id": obj.get("id"),
                "lock_version": obj.get("lockVersion"),
                "type_mapping": obj.get("typeMapping"),
                "type_mapping_name": obj.get("typeMappingName"),
            }
        )
        return _obj
