# coding: utf-8

"""
    Freestyle Sandboxes

     Freestyle Sandboxes lets you deploy your users or AIs code. **Get your API Key at [admin.freestyle.sh](https://admin.freestyle.sh)**  They are broken up into core 5 categories: [Web](#tag/web), [Execute](#tag/execute), [Cloudstate](#tag/cloudstate), [Git](#tag/git), and [Domains](#tag/domains).  [Web](#tag/web): Send us the code for the website, we'll provision the certificates and get it hosted  [Execute](#tag/execute): Send us a function, we'll run it and send you the output  [Cloudstate](#tag/cloudstate): Our Opensource JavaScript Runtime used for cloud functions with persistent state  [Domains](#tag/domains): Manage your domains, including verification and listing  [Git](#tag/git): Manage your git repositories 

    The version of the OpenAPI document: 0.1.0
    Contact: ben@freestyle.sh
    Generated by OpenAPI Generator (https://openapi-generator.tech)

    Do not edit the class manually.
"""  # noqa: E501


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

from pydantic import BaseModel, ConfigDict, Field, StrictBool, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from typing_extensions import Annotated
from _openapi_client.models.deployment_build_options import DeploymentBuildOptions
from _openapi_client.models.freestyle_network_permission import FreestyleNetworkPermission
from typing import Optional, Set
from typing_extensions import Self

class FreestyleDeployWebConfiguration(BaseModel):
    """
    FreestyleDeployWebConfiguration
    """ # noqa: E501
    entrypoint: Optional[StrictStr] = Field(default='index.js', description="The entrypoint file for the website")
    domains: Optional[List[StrictStr]] = Field(default=None, description="The custom domains for the website, eg. [\\\"subdomain.yourwebsite.com\\\"]. You may include a single *.style.dev domain here.")
    project_id: Optional[StrictStr] = Field(default=None, description="Project ID was our original way of tracking deployments together, it is now deprecated and will be removed in the future. Please use the domains field to specify the domains for your project.", alias="projectId")
    node_modules: Optional[Dict[str, StrictStr]] = Field(default=None, description="Node Modules to install for the website, a map of package names to versions, e.g. { \\\"express\\\": \\\"4.17.1\\\" }. If this and a package-lock.json are provided, the package-lock.json, bun.lockb, pnpm-lock.yaml, or yarn.lock is also provided, the versions here will override the versions in those lock files.", alias="nodeModules")
    env_vars: Optional[Dict[str, StrictStr]] = Field(default=None, description="The environment variables that the website can access e.g. { \\\"RESEND_API_KEY\\\": \\\"re_123456789\\\" }", alias="envVars")
    server_start_check: Optional[StrictBool] = Field(default=False, alias="serverStartCheck")
    network_permissions: Optional[List[FreestyleNetworkPermission]] = Field(default=None, alias="networkPermissions")
    build: Optional[DeploymentBuildOptions] = None
    timeout: Optional[Annotated[int, Field(strict=True, ge=0)]] = Field(default=None, description="Timeout for the deployment in seconds. If not provided, the default is 10 seconds.")
    __properties: ClassVar[List[str]] = ["entrypoint", "domains", "projectId", "nodeModules", "envVars", "serverStartCheck", "networkPermissions", "build", "timeout"]

    model_config = ConfigDict(
        populate_by_name=True,
        validate_assignment=True,
        protected_namespaces=(),
    )


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

    def to_json(self) -> str:
        """Returns the JSON representation of the model using alias"""
        # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
        return json.dumps(self.to_dict())

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

    def to_dict(self) -> Dict[str, Any]:
        """Return the dictionary representation of the model using alias.

        This has the following differences from calling pydantic's
        `self.model_dump(by_alias=True)`:

        * `None` is only added to the output dict for nullable fields that
          were set at model initialization. Other fields with value `None`
          are ignored.
        """
        excluded_fields: Set[str] = set([
        ])

        _dict = self.model_dump(
            by_alias=True,
            exclude=excluded_fields,
            exclude_none=True,
        )
        # override the default output from pydantic by calling `to_dict()` of each item in network_permissions (list)
        _items = []
        if self.network_permissions:
            for _item_network_permissions in self.network_permissions:
                if _item_network_permissions:
                    _items.append(_item_network_permissions.to_dict())
            _dict['networkPermissions'] = _items
        # override the default output from pydantic by calling `to_dict()` of build
        if self.build:
            _dict['build'] = self.build.to_dict()
        # set to None if entrypoint (nullable) is None
        # and model_fields_set contains the field
        if self.entrypoint is None and "entrypoint" in self.model_fields_set:
            _dict['entrypoint'] = None

        # set to None if domains (nullable) is None
        # and model_fields_set contains the field
        if self.domains is None and "domains" in self.model_fields_set:
            _dict['domains'] = None

        # set to None if project_id (nullable) is None
        # and model_fields_set contains the field
        if self.project_id is None and "project_id" in self.model_fields_set:
            _dict['projectId'] = None

        # set to None if network_permissions (nullable) is None
        # and model_fields_set contains the field
        if self.network_permissions is None and "network_permissions" in self.model_fields_set:
            _dict['networkPermissions'] = None

        # set to None if build (nullable) is None
        # and model_fields_set contains the field
        if self.build is None and "build" in self.model_fields_set:
            _dict['build'] = None

        # set to None if timeout (nullable) is None
        # and model_fields_set contains the field
        if self.timeout is None and "timeout" in self.model_fields_set:
            _dict['timeout'] = None

        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of FreestyleDeployWebConfiguration from a dict"""
        if obj is None:
            return None

        if not isinstance(obj, dict):
            return cls.model_validate(obj)

        _obj = cls.model_validate({
            "entrypoint": obj.get("entrypoint") if obj.get("entrypoint") is not None else 'index.js',
            "domains": obj.get("domains"),
            "projectId": obj.get("projectId"),
            "nodeModules": obj.get("nodeModules"),
            "envVars": obj.get("envVars"),
            "serverStartCheck": obj.get("serverStartCheck") if obj.get("serverStartCheck") is not None else False,
            "networkPermissions": [FreestyleNetworkPermission.from_dict(_item) for _item in obj["networkPermissions"]] if obj.get("networkPermissions") is not None else None,
            "build": DeploymentBuildOptions.from_dict(obj["build"]) if obj.get("build") is not None else None,
            "timeout": obj.get("timeout")
        })
        return _obj


