# coding: utf-8

"""
    Bluefin API

    Bluefin 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, StrictBool, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from bluefin_pro_api_client.models.create_order_request_sign_order_fields import CreateOrderRequestSignOrderFields
from bluefin_pro_api_client.models.order_time_in_force import OrderTimeInForce
from bluefin_pro_api_client.models.order_type import OrderType
from bluefin_pro_api_client.models.self_trade_prevention_type import SelfTradePreventionType
from typing import Optional, Set
from typing_extensions import Self

class CreateOrderRequest(BaseModel):
    """
    CreateOrderRequest
    """ # noqa: E501
    sign_order_fields: CreateOrderRequestSignOrderFields = Field(alias="signOrderFields")
    signature: StrictStr = Field(description="The signature of the request, encoded from the signOrderFields")
    order_hash: StrictStr = Field(description="The identifier of this order used for lookup. This should always be unique. Created by encoding the signOrderFields and then taking a hash.", alias="orderHash")
    client_order_id: Optional[StrictStr] = Field(default=None, description="The client-defined unique identifier of this order used for lookup. This should always be unique; however, the server will not gurantee this or impose any checks.", alias="clientOrderId")
    type: OrderType
    reduce_only: StrictBool = Field(description="Is this order to only reduce a position? Default false", alias="reduceOnly")
    post_only: StrictBool = Field(description="If set to TRUE, the order can only be a maker order", alias="postOnly")
    time_in_force: OrderTimeInForce = Field(alias="timeInForce")
    trigger_price_e9: Optional[StrictStr] = Field(default=None, description="Trigger price in base e9 for stop orders. This should always be a number", alias="triggerPriceE9")
    self_trade_prevention_type: Optional[SelfTradePreventionType] = Field(default=SelfTradePreventionType.TAKER, alias="selfTradePreventionType")
    __properties: ClassVar[List[str]] = ["signOrderFields", "signature", "orderHash", "clientOrderId", "type", "reduceOnly", "postOnly", "timeInForce", "triggerPriceE9", "selfTradePreventionType"]

    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 CreateOrderRequest 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 sign_order_fields
        if self.sign_order_fields:
            _dict['signOrderFields'] = self.sign_order_fields.to_dict()
        return _dict

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

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

        _obj = cls.model_validate({
            "signOrderFields": CreateOrderRequestSignOrderFields.from_dict(obj["signOrderFields"]) if obj.get("signOrderFields") is not None else None,
            "signature": obj.get("signature"),
            "orderHash": obj.get("orderHash"),
            "clientOrderId": obj.get("clientOrderId"),
            "type": obj.get("type"),
            "reduceOnly": obj.get("reduceOnly"),
            "postOnly": obj.get("postOnly"),
            "timeInForce": obj.get("timeInForce"),
            "triggerPriceE9": obj.get("triggerPriceE9"),
            "selfTradePreventionType": obj.get("selfTradePreventionType") if obj.get("selfTradePreventionType") is not None else SelfTradePreventionType.TAKER
        })
        return _obj


