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

    The Snowflake Services API is a REST API that you can use to access, update, and perform certain actions on Services 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.service._generated.models.service_spec import ServiceSpec

from datetime import datetime

from pydantic import BaseModel, ConfigDict, Field, StrictBool, StrictInt, StrictStr, field_validator

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

from typing_extensions import Annotated


class Service(BaseModel):

    name: Annotated[str, Field(strict=True)]

    compute_pool: StrictStr

    spec: ServiceSpec

    external_access_integrations: Optional[List[StrictStr]] = None

    auto_resume: Optional[StrictBool] = None

    min_instances: Optional[StrictInt] = None

    max_instances: Optional[StrictInt] = None

    query_warehouse: Optional[Annotated[str, Field(strict=True)]] = None

    comment: Optional[StrictStr] = None

    database_name: Optional[Annotated[str, Field(strict=True)]] = None

    schema_name: Optional[Annotated[str, Field(strict=True)]] = None

    owner: Optional[StrictStr] = None

    dns_name: Optional[StrictStr] = None

    created_on: Optional[datetime] = None

    updated_on: Optional[datetime] = None

    resumed_on: Optional[datetime] = None

    owner_role_type: Optional[StrictStr] = None

    __properties = [
        "name", "compute_pool", "spec", "external_access_integrations",
        "auto_resume", "min_instances", "max_instances", "query_warehouse",
        "comment", "database_name", "schema_name", "owner", "dns_name",
        "created_on", "updated_on", "resumed_on", "owner_role_type"
    ]

    @field_validator('name')
    def name_validate_regular_expression(cls, v):

        if not re.match(r"""^\"([^\"]|\"\")+\"|[a-zA-Z_][a-zA-Z0-9_$]*$""", v):
            raise ValueError(
                r"""must validate the regular expression /^"([^"]|"")+"|[a-zA-Z_][a-zA-Z0-9_$]*$/"""
            )
        return v

    @field_validator('query_warehouse')
    def query_warehouse_validate_regular_expression(cls, v):

        if v is None:
            return v
        if not re.match(r"""^\"([^\"]|\"\")+\"|[a-zA-Z_][a-zA-Z0-9_$]*$""", v):
            raise ValueError(
                r"""must validate the regular expression /^"([^"]|"")+"|[a-zA-Z_][a-zA-Z0-9_$]*$/"""
            )
        return v

    @field_validator('database_name')
    def database_name_validate_regular_expression(cls, v):

        if v is None:
            return v
        if not re.match(r"""^\"([^\"]|\"\")+\"|[a-zA-Z_][a-zA-Z0-9_$]*$""", v):
            raise ValueError(
                r"""must validate the regular expression /^"([^"]|"")+"|[a-zA-Z_][a-zA-Z0-9_$]*$/"""
            )
        return v

    @field_validator('schema_name')
    def schema_name_validate_regular_expression(cls, v):

        if v is None:
            return v
        if not re.match(r"""^\"([^\"]|\"\")+\"|[a-zA-Z_][a-zA-Z0-9_$]*$""", v):
            raise ValueError(
                r"""must validate the regular expression /^"([^"]|"")+"|[a-zA-Z_][a-zA-Z0-9_$]*$/"""
            )
        return v

    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) -> Service:
        """Create an instance of Service 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={
                           "owner",
                           "dns_name",
                           "created_on",
                           "updated_on",
                           "resumed_on",
                           "owner_role_type",
                       },
                       exclude_none=True))

        # override the default output from pydantic by calling `to_dict()` of spec
        if self.spec:
            _dict['spec'] = self.spec.to_dict()

        return _dict

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

        if obj is None:
            return None

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

        _obj = Service.parse_obj({
            "name":
            obj.get("name"),
            "compute_pool":
            obj.get("compute_pool"),
            "spec":
            ServiceSpec.from_dict(obj.get("spec"))
            if obj.get("spec") is not None else None,
            "external_access_integrations":
            obj.get("external_access_integrations"),
            "auto_resume":
            obj.get("auto_resume"),
            "min_instances":
            obj.get("min_instances"),
            "max_instances":
            obj.get("max_instances"),
            "query_warehouse":
            obj.get("query_warehouse"),
            "comment":
            obj.get("comment"),
            "database_name":
            obj.get("database_name"),
            "schema_name":
            obj.get("schema_name"),
            "owner":
            obj.get("owner"),
            "dns_name":
            obj.get("dns_name"),
            "created_on":
            obj.get("created_on"),
            "updated_on":
            obj.get("updated_on"),
            "resumed_on":
            obj.get("resumed_on"),
            "owner_role_type":
            obj.get("owner_role_type"),
        })

        return _obj


from typing import Optional, List, Dict

from snowflake.core.service._generated.models.service_spec import ServiceSpec


class ServiceModel():

    def __init__(
        self,
        name: str,
        compute_pool: str,
        spec: ServiceSpec,
        # optional properties
        external_access_integrations: Optional[List[str]] = None,
        auto_resume: Optional[bool] = None,
        min_instances: Optional[int] = None,
        max_instances: Optional[int] = None,
        query_warehouse: Optional[str] = None,
        comment: Optional[str] = None,
        database_name: Optional[str] = None,
        schema_name: Optional[str] = None,
        owner: Optional[str] = None,
        dns_name: Optional[str] = None,
        created_on: Optional[datetime] = None,
        updated_on: Optional[datetime] = None,
        resumed_on: Optional[datetime] = None,
        owner_role_type: Optional[str] = None,
    ):

        self.name = name
        self.compute_pool = compute_pool
        self.spec = spec
        self.external_access_integrations = external_access_integrations
        self.auto_resume = auto_resume
        self.min_instances = min_instances
        self.max_instances = max_instances
        self.query_warehouse = query_warehouse
        self.comment = comment
        self.database_name = database_name
        self.schema_name = schema_name
        self.owner = owner
        self.dns_name = dns_name
        self.created_on = created_on
        self.updated_on = updated_on
        self.resumed_on = resumed_on
        self.owner_role_type = owner_role_type

    __properties = [
        "name", "compute_pool", "spec", "external_access_integrations",
        "auto_resume", "min_instances", "max_instances", "query_warehouse",
        "comment", "database_name", "schema_name", "owner", "dns_name",
        "created_on", "updated_on", "resumed_on", "owner_role_type"
    ]

    def _to_model(self):
        return Service(
            name=self.name,
            compute_pool=self.compute_pool,
            spec=self.spec._to_model() if self.spec is not None else None,
            external_access_integrations=self.external_access_integrations,
            auto_resume=self.auto_resume,
            min_instances=self.min_instances,
            max_instances=self.max_instances,
            query_warehouse=self.query_warehouse,
            comment=self.comment,
            database_name=self.database_name,
            schema_name=self.schema_name,
            owner=self.owner,
            dns_name=self.dns_name,
            created_on=self.created_on,
            updated_on=self.updated_on,
            resumed_on=self.resumed_on,
            owner_role_type=self.owner_role_type,
        )

    @classmethod
    def _from_model(cls, model) -> ServiceModel:
        return ServiceModel(
            name=model.name,
            compute_pool=model.compute_pool,
            spec=ServiceSpecModel._from_model(model.spec)
            if model.spec is not None else None,
            external_access_integrations=model.external_access_integrations,
            auto_resume=model.auto_resume,
            min_instances=model.min_instances,
            max_instances=model.max_instances,
            query_warehouse=model.query_warehouse,
            comment=model.comment,
            database_name=model.database_name,
            schema_name=model.schema_name,
            owner=model.owner,
            dns_name=model.dns_name,
            created_on=model.created_on,
            updated_on=model.updated_on,
            resumed_on=model.resumed_on,
            owner_role_type=model.owner_role_type,
        )

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


Service._model_class = ServiceModel
