/*
 * 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 PositionLiquidationDto {
    /// Id representing the position liquidation
    #[serde(rename = "id")]
    pub id: uuid::Uuid,
    /// Id representing the subaccount that was liquidated
    #[serde(rename = "subaccountId")]
    pub subaccount_id: uuid::Uuid,
    /// Id representing the product that was liquidated
    #[serde(rename = "productId")]
    pub product_id: uuid::Uuid,
    /// Id representing the position that was liquidated
    #[serde(rename = "positionId")]
    pub position_id: uuid::Uuid,
    /// Liquidation mark price in USD expressed as a decimal (precision: 9)
    #[serde(rename = "liquidationPrice")]
    pub liquidation_price: String,
    #[serde(rename = "cause")]
    pub cause: models::PositionLiquidationCause,
    /// Position cost at the time of liquidation in USD expressed as a decimal (precision: 9)
    #[serde(rename = "cost")]
    pub cost: String,
    /// Funding charged in USD expressed as a decimal (precision: 9), undefined if not liquidated due to funding
    #[serde(rename = "fundingChargeUsd", skip_serializing_if = "Option::is_none")]
    pub funding_charge_usd: Option<String>,
    #[serde(rename = "positionSide")]
    pub position_side: models::PositionSide,
    /// Position liquidation timestamp (ms since Unix Epoch)
    #[serde(rename = "createdAt")]
    pub created_at: f64,
}

impl PositionLiquidationDto {
    pub fn new(
        id: uuid::Uuid,
        subaccount_id: uuid::Uuid,
        product_id: uuid::Uuid,
        position_id: uuid::Uuid,
        liquidation_price: String,
        cause: models::PositionLiquidationCause,
        cost: String,
        position_side: models::PositionSide,
        created_at: f64,
    ) -> PositionLiquidationDto {
        PositionLiquidationDto {
            id,
            subaccount_id,
            product_id,
            position_id,
            liquidation_price,
            cause,
            cost,
            funding_charge_usd: None,
            position_side,
            created_at,
        }
    }
}
