syntax = "proto3";

package worldmonitor.market.v1;

import "buf/validate/validate.proto";
import "sebuf/http/annotations.proto";

message StockAnalysisHeadline {
  string title = 1;
  string source = 2;
  string link = 3;
  int64 published_at = 4 [(sebuf.http.int64_encoding) = INT64_ENCODING_NUMBER];
}

message AnalyzeStockRequest {
  // Stock ticker symbol to analyze.
  string symbol = 1 [(sebuf.http.query) = { name: "symbol" },
    (buf.validate.field).required = true,
    (buf.validate.field).string.min_len = 1,
    (buf.validate.field).string.max_len = 32
  ];

  // Optional company display name used to disambiguate the symbol.
  string name = 2 [
    (sebuf.http.query) = { name: "name" },
    (buf.validate.field).string.max_len = 120
  ];

  // Whether to include recent news in the stock analysis.
  bool include_news = 3 [(sebuf.http.query) = { name: "include_news" }];
}

message AnalyzeStockResponse {
  bool available = 1;
  string symbol = 2;
  string name = 3;
  string display = 4;
  string currency = 5;

  double current_price = 6;
  double change_percent = 7;
  double signal_score = 8;
  string signal = 9;
  string trend_status = 10;
  string volume_status = 11;
  string macd_status = 12;
  string rsi_status = 13;
  string summary = 14;
  string action = 15;
  string confidence = 16;
  string technical_summary = 17;
  string news_summary = 18;
  string why_now = 19;

  repeated string bullish_factors = 20;
  repeated string risk_factors = 21;
  repeated double support_levels = 22;
  repeated double resistance_levels = 23;
  repeated StockAnalysisHeadline headlines = 24;

  double ma5 = 25;
  double ma10 = 26;
  double ma20 = 27;
  double ma60 = 28;
  double bias_ma5 = 29;
  double bias_ma10 = 30;
  double bias_ma20 = 31;
  double volume_ratio_5d = 32;
  double rsi_12 = 33;
  double macd_dif = 34;
  double macd_dea = 35;
  double macd_bar = 36;

  string provider = 37;
  string model = 38;
  bool fallback = 39;
  bool news_searched = 40;
  string generated_at = 41;
  string analysis_id = 42;
  int64 analysis_at = 43 [(sebuf.http.int64_encoding) = INT64_ENCODING_NUMBER];
  double stop_loss = 44;
  double take_profit = 45;
  string engine_version = 46;

  AnalystConsensus analyst_consensus = 47;
  PriceTarget price_target = 48;
  repeated UpgradeDowngrade recent_upgrades = 49;

  double dividend_yield = 50;
  double trailing_annual_dividend_rate = 51;
  int64 ex_dividend_date = 52 [(sebuf.http.int64_encoding) = INT64_ENCODING_NUMBER];
  optional double payout_ratio = 53;
  reserved 54;
  reserved "five_year_avg_dividend_yield";
  string dividend_frequency = 55;
  double dividend_cagr = 56;
}

message AnalystConsensus {
  int32 strong_buy = 1;
  int32 buy = 2;
  int32 hold = 3;
  int32 sell = 4;
  int32 strong_sell = 5;
  int32 total = 6;
  string period = 7;
}

message PriceTarget {
  optional double high = 1;
  optional double low = 2;
  optional double mean = 3;
  optional double median = 4;
  optional double current = 5;
  int32 number_of_analysts = 6;
}

message UpgradeDowngrade {
  string firm = 1;
  string to_grade = 2;
  string from_grade = 3;
  string action = 4;
  int64 epoch_grade_date = 5 [(sebuf.http.int64_encoding) = INT64_ENCODING_NUMBER];
}
