syntax = "proto3";

package alt.v1;

option go_package = "git.toki-labs.com/toki/alt/packages/contracts/gen/go/alt/v1;altv1";

import "alt/v1/common.proto";
import "alt/v1/market.proto";

enum BacktestRunStatus {
  BACKTEST_RUN_STATUS_UNSPECIFIED = 0;
  BACKTEST_RUN_STATUS_PENDING = 1;
  BACKTEST_RUN_STATUS_RUNNING = 2;
  BACKTEST_RUN_STATUS_SUCCEEDED = 3;
  BACKTEST_RUN_STATUS_FAILED = 4;
  BACKTEST_RUN_STATUS_CANCELED = 5;
}

message BacktestRunSpec {
  string strategy_id = 1;
  Market market = 2;
  Timeframe timeframe = 3;
  int64 from_unix_ms = 4;
  int64 to_unix_ms = 5;
}

message BacktestRun {
  string id = 1;
  BacktestRunSpec spec = 2;
  BacktestRunStatus status = 3;
  int64 created_at_unix_ms = 4;
  int64 updated_at_unix_ms = 5;
}

message StartBacktestRequest {
  BacktestRunSpec spec = 1;
}

message StartBacktestResponse {
  BacktestRun run = 1;
  ErrorInfo error = 2;
}

message GetBacktestRunRequest {
  string run_id = 1;
}

message GetBacktestRunResponse {
  BacktestRun run = 1;
  ErrorInfo error = 2;
}

message BacktestTrade {
  string instrument_id = 1;
  string side = 2;
  Quantity quantity = 3;
  Price price = 4;
  int64 timestamp_unix_ms = 5;
}

message BacktestPosition {
  string instrument_id = 1;
  Quantity quantity = 2;
  Price last_price = 3;
}

message BacktestSummaryMetrics {
  Price starting_cash = 1;
  Price ending_equity = 2;
  Decimal total_return = 3;
  int32 trade_count = 4;
}

message BacktestEquityPoint {
  int64 timestamp_unix_ms = 1;
  Price equity = 2;
}

message BacktestResult {
  string run_id = 1;
  Price starting_cash = 2;
  Price ending_equity = 3;
  repeated BacktestTrade trades = 4;
  repeated BacktestPosition positions = 5;
  BacktestSummaryMetrics summary = 6;
  repeated BacktestEquityPoint equity_curve = 7;
}

message GetBacktestResultRequest {
  string run_id = 1;
}

message GetBacktestResultResponse {
  BacktestResult result = 1;
  ErrorInfo error = 2;
}

message ListBacktestRunsRequest {
  BacktestRunStatus status = 1;
}

message ListBacktestRunsResponse {
  repeated BacktestRun runs = 1;
  ErrorInfo error = 2;
}

message GetBacktestRunDetailRequest {
  string run_id = 1;
}

message GetBacktestRunDetailResponse {
  BacktestRun run = 1;
  BacktestResult result = 2;
  ErrorInfo error = 3;
}

message CompareBacktestRunsRequest {
  repeated string run_ids = 1;
}

message CompareBacktestRunsResponse {
  repeated BacktestResult results = 1;
  ErrorInfo error = 2;
}
