# coding: utf-8

"""
    ARL Infrastructure API

    OpenAPI specification for ARL (Agentic RL) Infrastructure custom resources. This SDK provides models for WarmPool, Sandbox, and Task Kubernetes custom resources. 

    The version of the OpenAPI document: v1alpha1
    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, StrictStr, field_validator
from typing import Any, ClassVar, Dict, List, Optional
from typing import Optional, Set
from typing_extensions import Self

class TaskStep(BaseModel):
    """
    Task step definition. Each step can be either:  1. **FilePatch**: Create or modify a file    - Required: name, type=\"FilePatch\", path, content    - Example: {\"name\": \"write\", \"type\": \"FilePatch\", \"path\": \"/workspace/test.py\", \"content\": \"print('test')\"}  2. **Command**: Execute a command    - Required: name, type=\"Command\", command    - Optional: workDir, env    - Example: {\"name\": \"run\", \"type\": \"Command\", \"command\": [\"python\", \"test.py\"], \"env\": {\"DEBUG\": \"1\"}} 
    """ # noqa: E501
    command: Optional[List[StrictStr]] = Field(default=None, description="Command and arguments to execute (required for Command steps, ignored for FilePatch steps)")
    content: Optional[StrictStr] = Field(default=None, description="File content to write (required for FilePatch steps, ignored for Command steps)")
    env: Optional[Dict[str, StrictStr]] = Field(default=None, description="Environment variables as key-value pairs (optional, only for Command steps)")
    name: StrictStr = Field(description="Step identifier (unique within the task)")
    path: Optional[StrictStr] = Field(default=None, description="File path to create or modify (required for FilePatch steps, ignored for Command steps)")
    type: StrictStr = Field(description="Step type - either 'FilePatch' (create/modify files) or 'Command' (execute commands)")
    work_dir: Optional[StrictStr] = Field(default=None, description="Working directory for command execution (optional, only for Command steps)", alias="workDir")
    __properties: ClassVar[List[str]] = ["command", "content", "env", "name", "path", "type", "workDir"]

    @field_validator('type')
    def type_validate_enum(cls, value):
        """Validates the enum"""
        if value not in set(['FilePatch', 'Command']):
            raise ValueError("must be one of enum values ('FilePatch', 'Command')")
        return value

    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 TaskStep 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,
        )
        return _dict

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

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

        _obj = cls.model_validate({
            "command": obj.get("command"),
            "content": obj.get("content"),
            "env": obj.get("env"),
            "name": obj.get("name"),
            "path": obj.get("path"),
            "type": obj.get("type"),
            "workDir": obj.get("workDir")
        })
        return _obj


