# coding: utf-8

"""
Kaziro API

Kaziro Trading API Documentation

The version of the OpenAPI document: 1.0.5
Generated by OpenAPI Generator (https://openapi-generator.tech)

Do not edit the class manually.
"""  # noqa: E501

from __future__ import annotations

import json
import pprint
import re  # noqa: F401
from typing import Any, ClassVar, Dict, List, Optional, Set, Union

from pydantic import BaseModel, ConfigDict, Field, StrictFloat, StrictInt, StrictStr
from typing_extensions import Self


class Position(BaseModel):
    """
    Position
    """  # noqa: E501

    id: StrictStr = Field(description="Unique identifier for the position")
    market_id: StrictStr = Field(description="ID of the market this position belongs to")
    status: StrictStr = Field(description="Status of the position")
    side: StrictStr = Field(description="Side of the position based on the caller's user_id")
    request_size: Union[StrictFloat, StrictInt] = Field(description="Size of the request order")
    request_id: Optional[StrictStr] = Field(default=None, description="ID of the request order (order_id)")
    reply_size: Union[StrictFloat, StrictInt] = Field(description="Size of the reply order")
    reply_id: Optional[StrictStr] = Field(default=None, description="ID of the reply order (order_id)")
    protocol_id: StrictInt = Field(description="On-chain ID of the position")
    metadata: Optional[Dict[str, Any]] = Field(default=None, description="Additional metadata for the position")
    outcome: Optional[StrictInt] = Field(default=None, description="Result of the position. 1 for outcome 1, 2 for outcome 2, 0 for not yet determined, 3 for void")
    outcome_probability: Optional[Union[StrictFloat, StrictInt]] = Field(
        default=None, description="Probability of outcome 1. Provided for convenience. Can be determined from the size of the request and reply orders"
    )
    __properties: ClassVar[List[str]] = [
        "id",
        "market_id",
        "status",
        "side",
        "request_size",
        "request_id",
        "reply_size",
        "reply_id",
        "protocol_id",
        "metadata",
        "outcome",
        "outcome_probability",
    ]

    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 Position 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,
        )
        return _dict

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

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

        _obj = cls.model_validate(
            {
                "id": obj.get("id"),
                "market_id": obj.get("market_id"),
                "status": obj.get("status"),
                "side": obj.get("side"),
                "request_size": obj.get("request_size"),
                "request_id": obj.get("request_id"),
                "reply_size": obj.get("reply_size"),
                "reply_id": obj.get("reply_id"),
                "protocol_id": obj.get("protocol_id"),
                "metadata": obj.get("metadata"),
                "outcome": obj.get("outcome"),
                "outcome_probability": obj.get("outcome_probability"),
            }
        )
        return _obj
