# coding: utf-8
"""
    Snowflake Dynamic Table API

    The Snowflake Dynamic Table API is a REST API that you can use to access, update, and perform certain actions on Dynamic Tables resource in a Snowflake database.  # noqa: E501

    The version of the OpenAPI document: 0.0.1
    Contact: support@snowflake.com
    Generated by: https://openapi-generator.tech

    Do not edit this file manually.
"""

from __future__ import annotations
import pprint
import re  # noqa: F401
import json

import snowflake.core.dynamic_table._generated.models
from snowflake.core.dynamic_table._generated.models import *

from typing import Union

from importlib import import_module

from pydantic import BaseModel, ConfigDict

from typing import Any, ClassVar, Dict, List, Union


class TargetLag(BaseModel):

    __properties = ["type"]

    class Config:
        populate_by_name = True
        validate_assignment = True

    # JSON field name that stores the object type
    __discriminator_property_name: ClassVar[str] = 'type'

    # discriminator mappings
    __discriminator_value_class_map: ClassVar[Dict[str, str]] = {
        'DOWNSTREAM': 'DownstreamLag',
        'USER_DEFINED': 'UserDefinedLag'
    }

    @classmethod
    def get_discriminator_value(cls, obj: Dict[str, Any]) -> Optional[str]:
        """Returns the discriminator value (object type) of the data"""
        discriminator_value = obj[cls.__discriminator_property_name]
        if discriminator_value:
            return cls.__discriminator_value_class_map.get(discriminator_value)
        else:
            return None

    __discriminator_value_to_type: ClassVar[Dict[str, str]] = {
        'DownstreamLag': 'DOWNSTREAM',
        'UserDefinedLag': 'USER_DEFINED',
    }

    @classmethod
    def get_child_model_discriminator_value(cls, child_model: str) -> str:
        return cls.__discriminator_value_to_type[child_model]

    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) -> Union[DownstreamLag, UserDefinedLag]:
        """Create an instance of TargetLag 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 = dict(
            self._iter(to_dict=True,
                       by_alias=True,
                       exclude={},
                       exclude_none=True))

        return _dict

    @classmethod
    def from_dict(cls, obj: dict) -> Union[DownstreamLag, UserDefinedLag]:
        """Create an instance of TargetLag from a dict"""

        # look up the object type based on discriminator mapping
        object_type = cls.get_discriminator_value(obj)
        if object_type:
            klass = getattr(snowflake.core.dynamic_table._generated.models,
                            object_type)
            return klass.from_dict(obj)
        else:
            raise ValueError(
                "TargetLag failed to lookup discriminator value from " +
                json.dumps(obj) + ". Discriminator property name: " +
                cls.__discriminator_property_name + ", mapping: " +
                json.dumps(cls.__discriminator_value_class_map))


from typing import Optional, List, Dict


class TargetLagModel():

    def __init__(
            self,  # optional properties
    ):

        pass

    __properties = ["type"]

    def _to_model(self):
        return TargetLag()

    @classmethod
    def _from_model(cls, model) -> TargetLagModel:
        return model.__class__._model_class._from_model(model)

    def to_dict(self):
        """Returns the dictionary representation of the model using alias"""
        return self._to_model().to_dict()

    @classmethod
    def from_dict(cls,
                  obj: dict) -> Union[DownstreamLagModel, UserDefinedLagModel]:
        """Create an instance of TargetLag from a dict"""
        return cls._from_model(TargetLag.from_dict(obj))


TargetLag._model_class = TargetLagModel
