# coding: utf-8

"""
    The Jira Cloud platform REST API

    Jira Cloud platform REST API documentation

    The version of the OpenAPI document: 1001.0.0-SNAPSHOT-7ce0ee67a52d004425175cea962ad1c1c7200181
    Contact: ecosystem@atlassian.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 pydantic import BaseModel, ConfigDict, Field, StrictBool, StrictInt, StrictStr, field_validator
from typing import Any, ClassVar, Dict, List, Optional
from jira_client.models.bulk_change_owner_details import BulkChangeOwnerDetails
from jira_client.models.permission_details import PermissionDetails
from typing import Optional, Set
from typing_extensions import Self

class BulkEditShareableEntityRequest(BaseModel):
    """
    Details of a request to bulk edit shareable entity.
    """ # noqa: E501
    action: StrictStr = Field(description="Allowed action for bulk edit shareable entity")
    change_owner_details: Optional[BulkChangeOwnerDetails] = Field(default=None, description="The details of change owner action.", alias="changeOwnerDetails")
    entity_ids: List[StrictInt] = Field(description="The id list of shareable entities to be changed.", alias="entityIds")
    extend_admin_permissions: Optional[StrictBool] = Field(default=None, description="Whether the actions are executed by users with Administer Jira global permission.", alias="extendAdminPermissions")
    permission_details: Optional[PermissionDetails] = Field(default=None, description="The permission details to be changed.", alias="permissionDetails")
    __properties: ClassVar[List[str]] = ["action", "changeOwnerDetails", "entityIds", "extendAdminPermissions", "permissionDetails"]

    @field_validator('action')
    def action_validate_enum(cls, value):
        """Validates the enum"""
        if value not in set(['changeOwner', 'changePermission', 'addPermission', 'removePermission']):
            raise ValueError("must be one of enum values ('changeOwner', 'changePermission', 'addPermission', 'removePermission')")
        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 BulkEditShareableEntityRequest 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 change_owner_details
        if self.change_owner_details:
            _dict['changeOwnerDetails'] = self.change_owner_details.to_dict()
        # override the default output from pydantic by calling `to_dict()` of permission_details
        if self.permission_details:
            _dict['permissionDetails'] = self.permission_details.to_dict()
        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of BulkEditShareableEntityRequest 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"),
            "changeOwnerDetails": BulkChangeOwnerDetails.from_dict(obj["changeOwnerDetails"]) if obj.get("changeOwnerDetails") is not None else None,
            "entityIds": obj.get("entityIds"),
            "extendAdminPermissions": obj.get("extendAdminPermissions"),
            "permissionDetails": PermissionDetails.from_dict(obj["permissionDetails"]) if obj.get("permissionDetails") is not None else None
        })
        return _obj


