syntax = "proto3";

package dbag.energy.m7t.common.v7;

import "google/protobuf/timestamp.proto";
import "dbag/energy/m7t/validation/v7/validation.proto";

option java_multiple_files = true;
option java_package = "com.deutscheboerse.energy.m7.api.common.v7";

/**
 * Order open close indicator.
 */
enum OrderOpenCloseIndicator {
  ORDER_OPEN_CLOSE_INDICATOR_UNSPECIFIED = 0; // Open Close Indicator is not specified.
  ORDER_OPEN_CLOSE_INDICATOR_OPEN = 1; // Open.
  ORDER_OPEN_CLOSE_INDICATOR_CLOSE = 2; // Close.
}

/**
 * Order validity restrictions.
 */
enum OrderValidityRestriction {
  ORDER_VALIDITY_RESTRICTION_UNSPECIFIED = 0; // Order Validity Restriction is not specified.
  ORDER_VALIDITY_RESTRICTION_NONE = 1; // Order has no validity restriction.
  ORDER_VALIDITY_RESTRICTION_GFS = 2; // Good For Trading Session - Order is valid for the current trading session.
  ORDER_VALIDITY_RESTRICTION_GTD = 3; // Good Till Date - Order is valid until validity_date.
}

/**
 * Order aggressor indicator.
 */
enum OrderAggressorIndicator {
  ORDER_AGGRESSOR_INDICATOR_UNSPECIFIED = 0; // Aggressor Indicator is not specified.
  ORDER_AGGRESSOR_INDICATOR_YES = 1; // Trade aggressor.
  ORDER_AGGRESSOR_INDICATOR_NO = 2; // Trade originator.
  ORDER_AGGRESSOR_INDICATOR_UNKNOWN = 3; // Aggressor Indicator is unknown.
}

/**
 * Order execution restrictions.
 */
enum OrderExecutionRestriction {
  ORDER_EXECUTION_RESTRICTION_UNSPECIFIED = 0; // Order Execution Restriction is not specified.
  ORDER_EXECUTION_RESTRICTION_NOT_RESTRICTED = 1; // Order Execution is not restricted.
  ORDER_EXECUTION_RESTRICTION_AON = 2; // Order Execution is restricted to AON.
  ORDER_EXECUTION_RESTRICTION_FOK = 3; // Order Execution is restricted to FOK.
  ORDER_EXECUTION_RESTRICTION_IOC = 4; // Order Execution is restricted to IOC.
}

/**
 * Order states.
 */
enum OrderState {
  ORDER_STATE_UNSPECIFIED = 0; // Order state is not specified.
  ORDER_STATE_ACTIVE = 1; // Order is entered and is immediately exposed to the market execution.
  ORDER_STATE_INACTIVE = 2; // Order is deleted.
  ORDER_STATE_HIBERNATED = 3; // Order is entered into the backend system but is not exposed to the market.
  ORDER_STATE_UNKNOWN = 4; // Order state is unknown.
}

/**
 * Order types.
 */
enum OrderType {
  ORDER_TYPE_UNSPECIFIED = 0; // Order type is not specified.
  ORDER_TYPE_REGULAR = 1; // Regular limit order(default value).
  ORDER_TYPE_BLOCK = 2; // User-defined block order.
  ORDER_TYPE_BALANCE = 3; // Balance order.
  ORDER_TYPE_ICEBERG = 4; // Iceberg order.
  ORDER_TYPE_STOP = 5; // Stop order.
  ORDER_TYPE_EXCHANGE_PRE_ARRANGED = 6; // Pre-arranged trade on exchange.
  ORDER_TYPE_PRIVATE = 7; // Private and confidential order.
}


/**
 * Order sides.
 */
enum OrderSide {
  ORDER_SIDE_UNSPECIFIED = 0; // Order side is not specified.
  ORDER_SIDE_BUY = 1; // Order side is buy.
  ORDER_SIDE_SELL = 2; // Order side is sell.
}

/**
 * Defines the execution instruction for a whole list of orders.
 */
enum ExecutionInstruction {
  EXECUTION_INSTRUCTION_UNSPECIFIED = 0; // Execution instruction type is not specified.
  EXECUTION_INSTRUCTION_NONE = 1; // Execution instruction NONE - if any of the orders is not valid during the gateway validation, the whole list is rejected. Afterwards, the orders are treated independently in the Backend.
  EXECUTION_INSTRUCTION_VALID = 2; // Orders must pass the validation. If any is not valid the list is rejected.
  EXECUTION_INSTRUCTION_LINKED = 3; // Linked orders - the orders must be executed either all at once, or the whole list is rejected. All orders must have "FOK" restriction.
}

/**
  * Pre arranged order details.
 */
message PreArrangedOrderDetails {
  // Flag that indicates if the order is pre-arranged.
  optional bool pre_arranged = 1 [
    (energy.m7t.validation.v7.mandatory) = true
  ];

  // The account ID of the counterparty in case of a pre-arranged order.
  optional string pre_arranged_account_id = 2 [
    (energy.m7t.validation.v7.mandatory) = true,
    (energy.m7t.validation.v7.min_length) = 1,
    (energy.m7t.validation.v7.max_length) = 32
  ];
}

/**
 * Validity restriction details.
 */
message ValidityRestrictionDetails {
  // Validity restriction of the order. "GFS" is the default value.
  optional dbag.energy.m7t.common.v7.OrderValidityRestriction validity_restriction = 1 [
    (energy.m7t.validation.v7.mandatory) = true
  ];

  // Defines the date until which the order is valid. It is mandatory in case of "GTD" validity restriction.
  optional google.protobuf.Timestamp validity_date = 2 [
    (energy.m7t.validation.v7.mandatory_if) = {
      field_name: "validity_restriction",
      field_value: "ORDER_VALIDITY_RESTRICTION_GTD"
    },
    (energy.m7t.validation.v7.gt_now) = true
  ];
}

/**
 * Location specific information.
 */
message LocationDetails {
  // Location within the delivery area.
  optional string location = 1 [
    (energy.m7t.validation.v7.mandatory) = true,
    (energy.m7t.validation.v7.max_length) = 64
  ];

  // Indicates if the order is market based.
  optional bool market_based = 2[
    (energy.m7t.validation.v7.mandatory) = true
  ];

  // Reference to a contract between supplier and network operator.
  optional string contract_reference = 3 [
    (energy.m7t.validation.v7.max_length) = 64
  ];

  // Indicates the type of the network connected facility.
  optional string facility_type = 4 [
    (energy.m7t.validation.v7.max_length) = 64
  ];

  // Indicates min/max percentage value of order's usage.
  optional int32 usage_fraction = 5;
}

/*
 * Stop order details.
 */
message StopOrderDetails {
  // Stop price for stop limit orders.
  optional int64 stop_price = 1 [
    (energy.m7t.validation.v7.mandatory) = true
  ];
}

/*
 * Iceberg order details.
 */
message IcebergOrderDetails {
  // Peak price delta for Iceberg orders.
  optional int64 peak_price_delta = 1 [
    (energy.m7t.validation.v7.mandatory) = true
  ];

  // Displayed quantity of the Iceberg order.
  optional int32 displayed_quantity = 2 [
    (energy.m7t.validation.v7.mandatory) = true,
    (energy.m7t.validation.v7.min_value) = 0
  ];
}

/*
  * Metadata which can be used by the client.
 */
message ClientMetadata {
  // Text entered by the client.
  optional string text = 1 [
    (energy.m7t.validation.v7.max_length) = 250
  ];

  // Can be used by the client to define its own order ID.
  optional string client_order_id = 2 [
    (energy.m7t.validation.v7.min_length) = 1,
    (energy.m7t.validation.v7.max_length) = 40
  ];
}
