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

    The Snowflake Table API is a REST API that you can use to access, update, and perform certain actions on 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

from typing import Union

from snowflake.core.table._generated.models.constraint import Constraint

from pydantic import ConfigDict

from typing import Any, ClassVar, Dict, List


class PrimaryKey(Constraint):

    __properties = ["name", "column_names", "constraint_type"]

    class Config:
        populate_by_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) -> PrimaryKey:
        """Create an instance of PrimaryKey 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))

        _dict[
            'constraint_type'] = Constraint.get_child_model_discriminator_value(
                'PrimaryKey')

        return _dict

    @classmethod
    def from_dict(cls, obj: dict) -> PrimaryKey:
        """Create an instance of PrimaryKey from a dict"""

        if obj is None:
            return None

        if type(obj) is not dict:
            return PrimaryKey.parse_obj(obj)

        _obj = PrimaryKey.parse_obj({
            "name": obj.get("name"),
            "column_names": obj.get("column_names"),
        })

        return _obj


from typing import Optional, List, Dict

from snowflake.core.table._generated.models.constraint import Constraint


class PrimaryKeyModel(Constraint):

    def __init__(
        self,  # optional properties
        name: Optional[str] = None,
        column_names: Optional[List[str]] = None,
    ):
        super().__init__(
            name=name,
            column_names=column_names,
        )

    __properties = ["name", "column_names", "constraint_type"]

    def _to_model(self):
        return PrimaryKey(
            name=self.name,
            column_names=self.column_names,
        )

    @classmethod
    def _from_model(cls, model) -> PrimaryKeyModel:
        return PrimaryKeyModel(
            name=model.name,
            column_names=model.column_names,
        )

    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) -> PrimaryKeyModel:
        """Create an instance of PrimaryKey from a dict"""
        return cls._from_model(PrimaryKey.from_dict(obj))


PrimaryKey._model_class = PrimaryKeyModel
