/*
 * Websocket Subscription Schemas
 *
 * Schema definitions Websocket API subscriptions for Thalex exchange.
 *
 * The version of the OpenAPI document: 1.0.0
 *
 * Generated by: https://openapi-generator.tech
 */

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

/// OrderHistory : Historical order.
#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
pub struct OrderHistory {
    /// System order ID, use to identify in amend/cancel, and to match trades.
    #[serde(rename = "order_id")]
    pub order_id: String,
    #[serde(rename = "order_type")]
    pub order_type: models::OrderTypeEnum,
    /// Order instrument name.  Not present for combination orders. Refer to `legs` field instead.
    #[serde(rename = "instrument_name", skip_serializing_if = "Option::is_none")]
    pub instrument_name: Option<String>,
    /// List of legs for this combination order.  Not present for single-leg orders. Refer to `instrument_name` field instead.
    #[serde(rename = "legs", skip_serializing_if = "Option::is_none")]
    pub legs: Option<Vec<models::OrderHistoryLegsInner>>,
    #[serde(rename = "direction")]
    pub direction: models::DirectionEnum,
    /// Limit price. May be omitted if no price was supplied (e.g. for a market order).  For combination orders this specifies limit price per unit of the combination.
    #[serde(rename = "price", skip_serializing_if = "Option::is_none")]
    pub price: Option<rust_decimal::Decimal>,
    /// Order size (as inserted or amended to).  For combination orders this specifies the amount of units of the combination to trade.
    #[serde(rename = "amount")]
    pub amount: rust_decimal::Decimal,
    /// Part of the order that has been executed.  For combination orders this specifies the amount of units of the combination filled. Legs are filled proportionally to their quantities.
    #[serde(rename = "filled_amount")]
    pub filled_amount: rust_decimal::Decimal,
    /// Label supplied with insert. Can also be a number. Field is omitted if no label was supplied.
    #[serde(rename = "label", skip_serializing_if = "Option::is_none")]
    pub label: Option<String>,
    /// Client-supplied order id. Field is omitted if no client order id was supplied.
    #[serde(rename = "client_order_id", skip_serializing_if = "Option::is_none")]
    pub client_order_id: Option<rust_decimal::Decimal>,
    #[serde(rename = "status")]
    pub status: models::StatusEnum,
    /// All fills for this order.
    #[serde(rename = "fills")]
    pub fills: Vec<models::OrderFill>,
    #[serde(rename = "delete_reason")]
    pub delete_reason: models::OrderHistoryDeleteReasonEnum,
    #[serde(rename = "insert_reason")]
    pub insert_reason: models::InsertReasonEnum,
    /// If the order was triggered by a conditional order (stop order), the ID of that conditional order. Otherwise omitted.
    #[serde(
        rename = "conditional_order_id",
        skip_serializing_if = "Option::is_none"
    )]
    pub conditional_order_id: Option<String>,
    /// If the order was inserted by a bot, the ID of that bot. Otherwise omitted.
    #[serde(rename = "bot_id", skip_serializing_if = "Option::is_none")]
    pub bot_id: Option<String>,
    /// Creation time (Unix timestamp).
    #[serde(rename = "create_time")]
    pub create_time: rust_decimal::Decimal,
    /// Time when this order was closed or canceled (Unix timestamp).
    #[serde(rename = "close_time")]
    pub close_time: rust_decimal::Decimal,
    /// True if the order is a reduce only order, omitted otherwise.
    #[serde(rename = "reduce_only", skip_serializing_if = "Option::is_none")]
    pub reduce_only: Option<bool>,
}

impl OrderHistory {
    /// Historical order.
    pub fn new(
        order_id: String,
        order_type: models::OrderTypeEnum,
        direction: models::DirectionEnum,
        amount: rust_decimal::Decimal,
        filled_amount: rust_decimal::Decimal,
        status: models::StatusEnum,
        fills: Vec<models::OrderFill>,
        delete_reason: models::OrderHistoryDeleteReasonEnum,
        insert_reason: models::InsertReasonEnum,
        create_time: rust_decimal::Decimal,
        close_time: rust_decimal::Decimal,
    ) -> OrderHistory {
        OrderHistory {
            order_id,
            order_type,
            instrument_name: None,
            legs: None,
            direction,
            price: None,
            amount,
            filled_amount,
            label: None,
            client_order_id: None,
            status,
            fills,
            delete_reason,
            insert_reason,
            conditional_order_id: None,
            bot_id: None,
            create_time,
            close_time,
            reduce_only: None,
        }
    }
}
