# coding: utf-8

"""
    Teambition Open API

    Teambition Open API

    The version of the OpenAPI document: 1.0.0
    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, StrictFloat, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional, Union
from teambition_oapi_sdk.model.update_project_table_custom_field_request_actions_inner_from import UpdateProjectTableCustomFieldRequestActionsInnerFrom
from typing import Optional, Set
from typing_extensions import Self

class UpdateProjectTableCustomFieldRequestActionsInner(BaseModel):
    """
    UpdateProjectTableCustomFieldRequestActionsInner
    """ # noqa: E501
    action: StrictStr = Field(description="- addRow:       新增行 - removeRow:    删除行 - removeRowAll: 删除所有行 - updateRow:    更新行 - updateCell:   更新单元格 - clearCell:    清空单元格 - clearRow:     清空行 ")
    row_number: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="行号, 0 表示第一行, 多个action组合时，行号按前一次操作结果计算", alias="rowNumber")
    header_id: Optional[StrictStr] = Field(default=None, description="字段的表头ID，更新单元格时，和 headerName 二选一", alias="headerId")
    header_name: Optional[StrictStr] = Field(default=None, description="字段的表头名，如果有重复表头，只更新第一个，和 headerId 二选一", alias="headerName")
    var_from: Optional[UpdateProjectTableCustomFieldRequestActionsInnerFrom] = Field(default=None, alias="from")
    value: Optional[StrictStr] = Field(default=None, description="单元格的值")
    values: Optional[List[StrictStr]] = Field(default=None, description="新增/更新行，并且设置该行的值，适用于 addRow, updateRow 例如: { action:addRow, values=['1','2'] } ")
    value_map_json: Optional[StrictStr] = Field(default=None, description="键值对表达 values, 字符串格式 例如: { action:addRow, valueMapJson:'{\"headerId\": \"value1\", \"headerName\": \"value2\"}' } key 为 字段的表头ID 或者 表头名称 ", alias="valueMapJson")
    __properties: ClassVar[List[str]] = ["action", "rowNumber", "headerId", "headerName", "from", "value", "values", "valueMapJson"]

    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 UpdateProjectTableCustomFieldRequestActionsInner 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 var_from
        if self.var_from:
            _dict['from'] = self.var_from.to_dict()
        return _dict

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

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

        _obj = cls.model_validate({
            "action": obj.get("action"),
            "rowNumber": obj.get("rowNumber"),
            "headerId": obj.get("headerId"),
            "headerName": obj.get("headerName"),
            "from": UpdateProjectTableCustomFieldRequestActionsInnerFrom.from_dict(obj["from"]) if obj.get("from") is not None else None,
            "value": obj.get("value"),
            "values": obj.get("values"),
            "valueMapJson": obj.get("valueMapJson")
        })
        return _obj


