# coding: utf-8

"""
    AI Hub API

    The AI Hub REST API. See https://docs.instabase.com/api-sdk/ for more details.

    The version of the OpenAPI document: 0.1
    Contact: support@instabase.com
    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 typing import Any, ClassVar, Dict, List, Optional
from pydantic import BaseModel, StrictInt, StrictStr
from pydantic import Field
from aihub.models.run_app_request_settings import RunAppRequestSettings
try:
    from typing import Self
except ImportError:
    from typing_extensions import Self

class RunAppRequest(BaseModel):
    """
    RunAppRequest
    """ # noqa: E501
    app_name: Optional[StrictStr] = Field(default=None, description="Required unless using `app_id`. The name of the AI Hub app to run.")
    app_id: Optional[StrictStr] = Field(default=None, description="Required unless using `app_name`. The app ID of the AI Hub app to run.  <Tip>You can find an app ID in the app URL, such as http<span>s://</span>aihub.instabase.com/hub/apps/**528c36e8-ac5b-490d-a41b-7eec9c404b87**.</Tip> ")
    owner: Optional[StrictStr] = Field(default=None, description="The account that generated the app. If not specified, defaults to your AI Hub username.  For custom AI Hub apps belonging to you, accept the default. For public AI Hub apps published by Instabase, specify `instabase`. ")
    batch_id: Optional[StrictInt] = Field(default=None, description="Required unless using `input_dir`. The batch ID of a batch created with the [Batches endpoint.](/api-sdk/api-reference/batches/create-batch/) All files uploaded to the batch are used as input for the run.")
    input_dir: Optional[StrictStr] = Field(default=None, description="Required unless using `batch_id`. The path of the input folder in a connected drive or Instabase Drive. See [Specifying file paths.](/api-sdk/api-reference/run-reference#specifying-file-paths)")
    version: Optional[StrictStr] = Field(default=None, description="Version of the app to use. If not specified, defaults to the latest production version.")
    output_workspace: Optional[StrictStr] = Field(default=None, description="The workspace in which to run the app. The output is saved to the default drive of the specified workspace. If not defined, the default is:  - **Community accounts**: Runs in and saves to the personal workspace's Instabase Drive (`<USER-ID>/my-repo/Instabase Drive`).  - **Organization accounts**: Runs in and saves to the organization's default drive (`<ORGANIZATION-ID>/<USER-ID>/<default-drive>`). ")
    output_dir: Optional[StrictStr] = Field(default=None, description="Defines a specific location for the output to be saved in a connected drive or Instabase Drive. If defined, overrides the `output_workspace` value. See [Specifying file paths.](/api-sdk/run-reference/#specifying-file-paths)")
    settings: Optional[RunAppRequestSettings] = None
    __properties: ClassVar[List[str]] = ["app_name", "app_id", "owner", "batch_id", "input_dir", "version", "output_workspace", "output_dir", "settings"]

    model_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.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) -> Self:
        """Create an instance of RunAppRequest 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.
        """
        _dict = self.model_dump(
            by_alias=True,
            exclude={
            },
            exclude_none=True,
        )
        # override the default output from pydantic by calling `to_dict()` of settings
        if self.settings:
            _dict['settings'] = self.settings.to_dict()
        return _dict

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

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

        _obj = cls.model_validate({
            "app_name": obj.get("app_name"),
            "app_id": obj.get("app_id"),
            "owner": obj.get("owner"),
            "batch_id": obj.get("batch_id"),
            "input_dir": obj.get("input_dir"),
            "version": obj.get("version"),
            "output_workspace": obj.get("output_workspace"),
            "output_dir": obj.get("output_dir"),
            "settings": RunAppRequestSettings.from_dict(obj.get("settings")) if obj.get("settings") is not None else None
        })
        return _obj


