/*
 * 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};

#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
pub struct ConditionalOrder {
    /// Unique ID, use to identify in cancel
    #[serde(rename = "order_id")]
    pub order_id: String,
    #[serde(rename = "instrument_name")]
    pub instrument_name: String,
    #[serde(rename = "direction")]
    pub direction: models::DirectionEnum,
    /// Size of the order when activated
    #[serde(rename = "amount")]
    pub amount: rust_decimal::Decimal,
    #[serde(rename = "target")]
    pub target: models::TargetEnum,
    /// Trigger price at which the order will be activated
    #[serde(rename = "stop_price")]
    pub stop_price: rust_decimal::Decimal,
    /// For stop limit order, the price at which the order will be placed
    #[serde(rename = "limit_price", skip_serializing_if = "Option::is_none")]
    pub limit_price: Option<rust_decimal::Decimal>,
    /// For bracket order, the price at which profit will be taken (upper activation price)
    #[serde(rename = "bracket_price", skip_serializing_if = "Option::is_none")]
    pub bracket_price: Option<rust_decimal::Decimal>,
    /// For trailing stop loss, the callback rate as a ratio (e.g. 0.05 for 5%)
    #[serde(
        rename = "trailing_stop_callback_rate",
        skip_serializing_if = "Option::is_none"
    )]
    pub trailing_stop_callback_rate: Option<rust_decimal::Decimal>,
    /// Optional user label
    #[serde(rename = "label", skip_serializing_if = "Option::is_none")]
    pub label: Option<String>,
    #[serde(rename = "status")]
    pub status: models::ConditionalOrderStatusEnum,
    #[serde(rename = "create_time")]
    pub create_time: rust_decimal::Decimal,
    /// Time of last update (conversion or change of trailing stop price)
    #[serde(rename = "update_time")]
    pub update_time: rust_decimal::Decimal,
    /// Time of trigger
    #[serde(rename = "convert_time", skip_serializing_if = "Option::is_none")]
    pub convert_time: Option<rust_decimal::Decimal>,
    /// System order ID of the created order.
    #[serde(rename = "converted_order_id", skip_serializing_if = "Option::is_none")]
    pub converted_order_id: Option<String>,
    /// If conversion failed, the reason
    #[serde(rename = "reject_reason", skip_serializing_if = "Option::is_none")]
    pub reject_reason: Option<String>,
    #[serde(rename = "reduce_only")]
    pub reduce_only: bool,
}

impl ConditionalOrder {
    pub fn new(
        order_id: String,
        instrument_name: String,
        direction: models::DirectionEnum,
        amount: rust_decimal::Decimal,
        target: models::TargetEnum,
        stop_price: rust_decimal::Decimal,
        status: models::ConditionalOrderStatusEnum,
        create_time: rust_decimal::Decimal,
        update_time: rust_decimal::Decimal,
        reduce_only: bool,
    ) -> ConditionalOrder {
        ConditionalOrder {
            order_id,
            instrument_name,
            direction,
            amount,
            target,
            stop_price,
            limit_price: None,
            bracket_price: None,
            trailing_stop_callback_rate: None,
            label: None,
            status,
            create_time,
            update_time,
            convert_time: None,
            converted_order_id: None,
            reject_reason: None,
            reduce_only,
        }
    }
}
