/*
 * Ethereal Exchange API
 *
 * Ethereal HTTP API for real-time trading, order management, and market data access.
 *
 * The version of the OpenAPI document: 0.1.0
 *
 * Generated by: https://openapi-generator.tech
 */

use crate::models;
use serde::{Deserialize, Serialize};

#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
pub struct PositionDto {
    /// Id representing the position
    #[serde(rename = "id")]
    pub id: uuid::Uuid,
    /// Current cost of the position in USD expressed as a decimal (precision: 9)
    #[serde(rename = "cost")]
    pub cost: String,
    /// Position size in native units expressed as a decimal (precision: 9)
    #[serde(rename = "size")]
    pub size: String,
    /// Charged but unapplied funding on position, negative if paid, expressed as a decimal (precision: 9)
    #[serde(rename = "fundingUsd")]
    pub funding_usd: String,
    /// Charged and applied funding on position, negative if paid, expressed as a decimal (precision: 9)
    #[serde(rename = "fundingAccruedUsd")]
    pub funding_accrued_usd: String,
    /// Fees accrued in USD expressed as a decimal (precision: 9)
    #[serde(rename = "feesAccruedUsd")]
    pub fees_accrued_usd: String,
    /// Realized PnL in USD expressed as a decimal (precision: 9)
    #[serde(rename = "realizedPnl")]
    pub realized_pnl: String,
    /// Cumulative USD value of all position increases expressed as a decimal (precision: 9)
    #[serde(rename = "totalIncreaseNotional")]
    pub total_increase_notional: String,
    /// Cumulative quantity of all position increases expressed as a decimal (precision: 9)
    #[serde(rename = "totalIncreaseQuantity")]
    pub total_increase_quantity: String,
    /// Cumulative USD value of all position decreases expressed as a decimal (precision: 9)
    #[serde(rename = "totalDecreaseNotional")]
    pub total_decrease_notional: String,
    /// Cumulative quantity of all position decreases expressed as a decimal (precision: 9)
    #[serde(rename = "totalDecreaseQuantity")]
    pub total_decrease_quantity: String,
    #[serde(rename = "side")]
    pub side: models::PositionSide,
    /// Id of product to this position belongs to
    #[serde(rename = "productId")]
    pub product_id: uuid::Uuid,
    /// Position last updated timestamp (ms since Unix Epoch)
    #[serde(rename = "updatedAt")]
    pub updated_at: f64,
    /// Position creation timestamp (ms since Unix Epoch)
    #[serde(rename = "createdAt")]
    pub created_at: f64,
    /// Whether the position was liquidated
    #[serde(rename = "isLiquidated")]
    pub is_liquidated: bool,
    /// Product price at the time of liquidation (undefined if not liquidated, precision: 9)
    #[serde(rename = "liquidationPrice", skip_serializing_if = "Option::is_none")]
    pub liquidation_price: Option<String>,
}

impl PositionDto {
    pub fn new(
        id: uuid::Uuid,
        cost: String,
        size: String,
        funding_usd: String,
        funding_accrued_usd: String,
        fees_accrued_usd: String,
        realized_pnl: String,
        total_increase_notional: String,
        total_increase_quantity: String,
        total_decrease_notional: String,
        total_decrease_quantity: String,
        side: models::PositionSide,
        product_id: uuid::Uuid,
        updated_at: f64,
        created_at: f64,
        is_liquidated: bool,
    ) -> PositionDto {
        PositionDto {
            id,
            cost,
            size,
            funding_usd,
            funding_accrued_usd,
            fees_accrued_usd,
            realized_pnl,
            total_increase_notional,
            total_increase_quantity,
            total_decrease_notional,
            total_decrease_quantity,
            side,
            product_id,
            updated_at,
            created_at,
            is_liquidated,
            liquidation_price: None,
        }
    }
}
