text: # Auto-generated at 2021-09-27T17:01:29.706716+08:00
  # from: Justice Platform Service (3.24.0)
  
  # Copyright (c) 2018 - 2021 AccelByte Inc. All Rights Reserved.
  # This is licensed software from AccelByte Inc, for limitations
  # and restrictions contact your company contract manager.
  
  # pylint: disable=duplicate-code
  # pylint: disable=line-too-long
  # pylint: disable=missing-function-docstring
  # pylint: disable=missing-module-docstring
  # pylint: disable=too-many-arguments
  # pylint: disable=too-many-branches
  # pylint: disable=too-many-instance-attributes
  # pylint: disable=too-many-lines
  # pylint: disable=too-many-locals
  # pylint: disable=too-many-public-methods
  # pylint: disable=too-many-return-statements
  # pylint: disable=too-many-statements
  # pylint: disable=unused-import
  
  from __future__ import annotations
  from typing import Any, Dict, List, Optional, Tuple, Union
  
  from .....core import Operation
  from .....core import HttpResponse
  
  from ...models import ErrorEntity
  from ...models import FulfillmentRequest
  from ...models import FulfillmentResult
  
  
  class FulfillItem(Operation):
      """Fulfill item (fulfillItem)
  
      Properties:
          url: /platform/admin/namespaces/{namespace}/users/{userId}/fulfillment
  
          method: POST
  
          tags: Fulfillment
  
          consumes: ["application/json"]
  
          produces: ["application/json"]
  
          security: bearer
  
          body: (body) OPTIONAL FulfillmentRequest in body
  
          namespace: (namespace) REQUIRED str in path
  
          user_id: (userId) REQUIRED str in path
  
      Responses:
          200: OK - FulfillmentResult (successful operation)
  
          400: Bad Request - ErrorEntity (ErrorCode: 35121 | ErrorMessage: Transaction amount [{actualAmount}] exceed max amount [{maxAmount}] per day)
  
          404: Not Found - ErrorEntity (ErrorCode: 30341 | ErrorMessage: Item [{itemId}] does not exist in namespace [{namespace}])
  
          409: Conflict - ErrorEntity (ErrorCode: 20006 | ErrorMessage: optimistic lock)
      """
  
      # region fields
  
      _url: str = "/platform/admin/namespaces/{namespace}/users/{userId}/fulfillment"
      _method: str = "POST"
      _consumes: List[str] = ["application/json"]
      _produces: List[str] = ["application/json"]
      _security: Optional[str] = "bearer"
      _location_query: str = None
  
      body: FulfillmentRequest                                                                       # OPTIONAL in [body]
      namespace: str                                                                                 # REQUIRED in [path]
      user_id: str                                                                                   # REQUIRED in [path]
  
      # endregion fields
  
      # region properties
  
      @property
      def url(self) -> str:
          return self._url
  
      @property
      def method(self) -> str:
          return self._method
  
      @property
      def consumes(self) -> List[str]:
          return self._consumes
  
      @property
      def produces(self) -> List[str]:
          return self._produces
  
      @property
      def security(self) -> Optional[str]:
          return self._security
  
      @property
      def location_query(self) -> str:
          return self._location_query
  
      # endregion properties
  
      # region get methods
  
      def get_full_url(self, base_url: Union[None, str] = None) -> str:
          result = base_url if base_url is not None else ""
  
          # path params
          url = self.url
          for k, v in self.get_path_params().items():
              url = url.replace(f"{{{k}}}", v)
          result += url
  
          return result
  
      # noinspection PyMethodMayBeStatic
      def get_all_required_fields(self) -> List[str]:
          return [
              "namespace",
              "user_id",
          ]
  
      # endregion get methods
  
      # region get_x_params methods
  
      def get_all_params(self) -> dict:
          return {
              "body": self.get_body_params(),
              "path": self.get_path_params(),
          }
  
      def get_body_params(self) -> Any:
          return self.body.to_dict()
  
      def get_path_params(self) -> dict:
          result = {}
          if hasattr(self, "namespace"):
              result["namespace"] = self.namespace
          if hasattr(self, "user_id"):
              result["userId"] = self.user_id
          return result
  
      # endregion get_x_params methods
  
      # region is/has methods
  
      def is_valid(self) -> bool:
          if not hasattr(self, "namespace") or self.namespace is None:
              return False
          if not hasattr(self, "user_id") or self.user_id is None:
              return False
          return True
  
      # endregion is/has methods
  
      # region with_x methods
  
      def with_body(self, value: FulfillmentRequest) -> FulfillItem:
          self.body = value
          return self
  
      def with_namespace(self, value: str) -> FulfillItem:
          self.namespace = value
          return self
  
      def with_user_id(self, value: str) -> FulfillItem:
          self.user_id = value
          return self
  
      # endregion with_x methods
  
      # region to methods
  
      def to_dict(self, include_empty: bool = False) -> dict:
          result = {}
          if hasattr(self, "body") and self.body:
              result["body"] = self.body.to_dict(include_empty=include_empty)
          elif include_empty:
              result["body"] = FulfillmentRequest()
          if hasattr(self, "namespace") and self.namespace:
              result["namespace"] = str(self.namespace)
          elif include_empty:
              result["namespace"] = str()
          if hasattr(self, "user_id") and self.user_id:
              result["userId"] = str(self.user_id)
          elif include_empty:
              result["userId"] = str()
          return result
  
      # endregion to methods
  
      # region response methods
  
      # noinspection PyMethodMayBeStatic
      def parse_response(self, code: int, content_type: str, content: Any) -> Tuple[Union[None, FulfillmentResult], Union[None, ErrorEntity]]:
          """Parse the given response.
  
          200: OK - FulfillmentResult (successful operation)
  
          400: Bad Request - ErrorEntity (ErrorCode: 35121 | ErrorMessage: Transaction amount [{actualAmount}] exceed max amount [{maxAmount}] per day)
  
          404: Not Found - ErrorEntity (ErrorCode: 30341 | ErrorMessage: Item [{itemId}] does not exist in namespace [{namespace}])
  
          409: Conflict - ErrorEntity (ErrorCode: 20006 | ErrorMessage: optimistic lock)
          """
          if code == 200:
              return FulfillmentResult.create_from_dict(content), None
          if code == 400:
              return None, ErrorEntity.create_from_dict(content)
          if code == 404:
              return None, ErrorEntity.create_from_dict(content)
          if code == 409:
              return None, ErrorEntity.create_from_dict(content)
          was_handled, undocumented_response = HttpResponse.try_create_undocumented_response(code, content)
          if was_handled:
              return None, undocumented_response
          return None, HttpResponse.create_unhandled_error()
  
      # endregion response methods
  
      # region static methods
  
      @classmethod
      def create(
          cls,
          namespace: str,
          user_id: str,
          body: Optional[FulfillmentRequest] = None,
      ) -> FulfillItem:
          instance = cls()
          instance.namespace = namespace
          instance.user_id = user_id
          if body is not None:
              instance.body = body
          return instance
  
      @classmethod
      def create_from_dict(cls, dict_: dict, include_empty: bool = False) -> FulfillItem:
          instance = cls()
          if "body" in dict_ and dict_["body"] is not None:
              instance.body = FulfillmentRequest.create_from_dict(dict_["body"], include_empty=include_empty)
          elif include_empty:
              instance.body = FulfillmentRequest()
          if "namespace" in dict_ and dict_["namespace"] is not None:
              instance.namespace = str(dict_["namespace"])
          elif include_empty:
              instance.namespace = str()
          if "userId" in dict_ and dict_["userId"] is not None:
              instance.user_id = str(dict_["userId"])
          elif include_empty:
              instance.user_id = str()
          return instance
  
      @staticmethod
      def get_field_info() -> Dict[str, str]:
          return {
              "body": "body",
              "namespace": "namespace",
              "userId": "user_id",
          }
  
      # endregion static methods
  