# 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 datetime import datetime
from pydantic import BaseModel, ConfigDict, Field, StrictInt, StrictStr, field_validator
from typing import Any, ClassVar, Dict, List, Optional
from typing_extensions import Annotated
from teambition_oapi_sdk.model.create_task_v3_request_reminders_inner import CreateTaskV3RequestRemindersInner
from teambition_oapi_sdk.model.post_v3_projectplan_task_plans_tasks_request_customfields_inner import PostV3ProjectplanTaskPlansTasksRequestCustomfieldsInner
from typing import Optional, Set
from typing_extensions import Self

class PostV3ProjectplanTaskPlansTasksRequest(BaseModel):
    """
    
    """ # noqa: E501
    project_id: Optional[StrictStr] = Field(default=None, description="项目id", alias="projectId")
    content: Optional[Annotated[str, Field(strict=True, max_length=500)]] = Field(default=None, description="任务标题")
    executor_id: Optional[StrictStr] = Field(default=None, description="执行者id", alias="executorId")
    involve_members: Optional[List[StrictStr]] = Field(default=None, description="参与者用户ID列表", alias="involveMembers")
    stage_id: Optional[StrictStr] = Field(default=None, description="任务列id", alias="stageId")
    tasklist_id: Optional[StrictStr] = Field(default=None, description="任务组id", alias="tasklistId")
    taskflowstatus_id: Optional[StrictStr] = Field(default=None, description="任务状态id", alias="taskflowstatusId")
    start_date: Optional[datetime] = Field(default=None, description="开始日期", alias="startDate")
    due_date: Optional[datetime] = Field(default=None, description="截止日期", alias="dueDate")
    note: Optional[StrictStr] = Field(default=None, description="任务备注")
    note_render_mode: Optional[StrictStr] = Field(default=None, description="任务备注渲染模式, markdown, rtf, rtf就是富文本，富文本需要提交 rtfValueToken", alias="noteRenderMode")
    note_rtf_value_token: Optional[StrictStr] = Field(default=None, description="任务备注富文本内容，格式仅限从 rtf/render 接口中获取的 rtfValue", alias="noteRtfValueToken")
    priority: Optional[StrictInt] = Field(default=None, description="执行优先级")
    parent_task_id: Optional[StrictStr] = Field(default=None, description="父任务id", alias="parentTaskId")
    progress: Optional[StrictInt] = Field(default=None, description="进度")
    visible: Optional[StrictStr] = Field(default=None, description="任务的可见性规则 involves | members")
    sprint_id: Optional[StrictStr] = Field(default=None, description="迭代id", alias="sprintId")
    tag_ids: Optional[List[StrictStr]] = Field(default=None, description="标签id列表", alias="tagIds")
    story_point: Optional[StrictStr] = Field(default=None, alias="storyPoint")
    scenariofieldconfig_id: Optional[StrictStr] = Field(default=None, description="任务类型id", alias="scenariofieldconfigId")
    scenariofieldconfig_alias: Optional[StrictStr] = Field(default=None, description="任务类型别名(如果提供任务类型id 则忽略)", alias="scenariofieldconfigAlias")
    reminders: Optional[Annotated[List[CreateTaskV3RequestRemindersInner], Field(max_length=9)]] = None
    customfields: Optional[List[PostV3ProjectplanTaskPlansTasksRequestCustomfieldsInner]] = Field(default=None, description="自定义字段值列表")
    __properties: ClassVar[List[str]] = ["projectId", "content", "executorId", "involveMembers", "stageId", "tasklistId", "taskflowstatusId", "startDate", "dueDate", "note", "noteRenderMode", "noteRtfValueToken", "priority", "parentTaskId", "progress", "visible", "sprintId", "tagIds", "storyPoint", "scenariofieldconfigId", "scenariofieldconfigAlias", "reminders", "customfields"]

    @field_validator('note_render_mode')
    def note_render_mode_validate_enum(cls, value):
        """Validates the enum"""
        if value is None:
            return value

        if value not in set(['markdown', 'rtf']):
            raise ValueError("must be one of enum values ('markdown', 'rtf')")
        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 PostV3ProjectplanTaskPlansTasksRequest 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 reminders (list)
        _items = []
        if self.reminders:
            for _item_reminders in self.reminders:
                if _item_reminders:
                    _items.append(_item_reminders.to_dict())
            _dict['reminders'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in customfields (list)
        _items = []
        if self.customfields:
            for _item_customfields in self.customfields:
                if _item_customfields:
                    _items.append(_item_customfields.to_dict())
            _dict['customfields'] = _items
        return _dict

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

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

        _obj = cls.model_validate({
            "projectId": obj.get("projectId"),
            "content": obj.get("content"),
            "executorId": obj.get("executorId"),
            "involveMembers": obj.get("involveMembers"),
            "stageId": obj.get("stageId"),
            "tasklistId": obj.get("tasklistId"),
            "taskflowstatusId": obj.get("taskflowstatusId"),
            "startDate": obj.get("startDate"),
            "dueDate": obj.get("dueDate"),
            "note": obj.get("note"),
            "noteRenderMode": obj.get("noteRenderMode"),
            "noteRtfValueToken": obj.get("noteRtfValueToken"),
            "priority": obj.get("priority"),
            "parentTaskId": obj.get("parentTaskId"),
            "progress": obj.get("progress"),
            "visible": obj.get("visible"),
            "sprintId": obj.get("sprintId"),
            "tagIds": obj.get("tagIds"),
            "storyPoint": obj.get("storyPoint"),
            "scenariofieldconfigId": obj.get("scenariofieldconfigId"),
            "scenariofieldconfigAlias": obj.get("scenariofieldconfigAlias"),
            "reminders": [CreateTaskV3RequestRemindersInner.from_dict(_item) for _item in obj["reminders"]] if obj.get("reminders") is not None else None,
            "customfields": [PostV3ProjectplanTaskPlansTasksRequestCustomfieldsInner.from_dict(_item) for _item in obj["customfields"]] if obj.get("customfields") is not None else None
        })
        return _obj


