syntax = "proto3";
package band.tunnel.v1beta1;

import "amino/amino.proto";
import "cosmos/base/v1beta1/coin.proto";
import "cosmos_proto/cosmos.proto";
import "gogoproto/gogo.proto";
import "google/protobuf/any.proto";

import "band/feeds/v1beta1/encoder.proto";
import "band/feeds/v1beta1/feeds.proto";

option go_package            = "github.com/bandprotocol/chain/v3/x/tunnel/types";
option (gogoproto.equal_all) = true;

// Tunnel contains the information of the tunnel that is created by the user
message Tunnel {
  option (gogoproto.equal) = true;

  // id is the tunnel ID
  uint64 id = 1 [(gogoproto.customname) = "ID"];
  // sequence is representing the sequence of the tunnel packet.
  uint64 sequence = 2;
  // route is the route for delivering the signal prices
  google.protobuf.Any route = 3 [(cosmos_proto.accepts_interface) = "RouteI"];
  // fee_payer is the address of the fee payer
  string fee_payer = 4 [(cosmos_proto.scalar) = "cosmos.AddressString"];
  // signal_deviations is the list of signal deviations
  repeated SignalDeviation signal_deviations = 5 [(gogoproto.nullable) = false];
  // interval is the interval for delivering the signal prices
  uint64 interval = 6;
  // total_deposit is the total deposit on the tunnel.
  repeated cosmos.base.v1beta1.Coin total_deposit = 7 [
    (gogoproto.nullable)     = false,
    (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins",
    (amino.dont_omitempty)   = true
  ];
  // is_active is the flag to indicate if the tunnel is active
  bool is_active = 8;
  // created_at is the timestamp when the tunnel is created
  int64 created_at = 9;
  // creator is the address of the creator
  string creator = 10 [(cosmos_proto.scalar) = "cosmos.AddressString"];
}

// LatestPrices is the type for prices that tunnel produces
message LatestPrices {
  option (gogoproto.equal) = true;

  // tunnel_id is the tunnel ID
  uint64 tunnel_id = 1 [(gogoproto.customname) = "TunnelID"];
  // prices is the list of prices information from feeds module.
  repeated band.feeds.v1beta1.Price prices = 2 [(gogoproto.nullable) = false];
  // last_interval is the last interval when the signal prices are produced by interval trigger
  int64 last_interval = 3;
}

// TotalFees is the type for the total fees collected by the tunnel
message TotalFees {
  option (gogoproto.equal) = true;

  // total_base_packet_fee is the total base packet fee collected by the tunnel
  repeated cosmos.base.v1beta1.Coin total_base_packet_fee = 1
      [(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"];
}

// Packet is the packet that tunnel produces
message Packet {
  // tunnel_id is the tunnel ID
  uint64 tunnel_id = 1 [(gogoproto.customname) = "TunnelID"];
  // sequence is representing the sequence of the tunnel packet.
  uint64 sequence = 2;
  // prices is the list of prices information from feeds module.
  repeated band.feeds.v1beta1.Price prices = 3 [(gogoproto.nullable) = false];
  // receipt represents the confirmation of the packet delivery to the destination via the specified route.
  google.protobuf.Any receipt = 4 [(cosmos_proto.accepts_interface) = "PacketReceiptI"];
  // created_at is the timestamp when the packet is created
  int64 created_at = 5;
}

// Deposit defines an amount deposited by an account address to the tunnel.
message Deposit {
  option (gogoproto.equal) = true;

  // tunnel_id defines the unique id of the tunnel.
  uint64 tunnel_id = 1 [(gogoproto.customname) = "TunnelID"];
  // depositor defines the deposit addresses from the proposals.
  string depositor = 2 [(cosmos_proto.scalar) = "cosmos.AddressString"];
  // amount to be deposited by depositor.
  repeated cosmos.base.v1beta1.Coin amount = 3 [
    (gogoproto.nullable)     = false,
    (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins",
    (amino.dont_omitempty)   = true
  ];
}

// SignalDeviation is the type for a signal with soft and hard deviation
message SignalDeviation {
  option (gogoproto.equal) = true;

  // signal_id is the signal ID
  string signal_id = 1 [(gogoproto.customname) = "SignalID"];
  // soft_deviation_bps is the soft deviation in basis points
  uint64 soft_deviation_bps = 2 [(gogoproto.customname) = "SoftDeviationBPS"];
  // hard_deviation_bps is the hard deviation in basis points
  uint64 hard_deviation_bps = 3 [(gogoproto.customname) = "HardDeviationBPS"];
}

// TunnelSignatureOrder defines a general signature order for sending signature to tss group.
message TunnelSignatureOrder {
  option (gogoproto.goproto_getters) = false;

  // sequence is the sequence of the packet
  uint64 sequence = 1;
  // prices is the list of prices information from feeds module.
  repeated band.feeds.v1beta1.Price prices = 2 [(gogoproto.nullable) = false];
  // created_at is the timestamp when the packet is created
  int64 created_at = 3;
  // encoder is the mode of encoding data.
  band.feeds.v1beta1.Encoder encoder = 4;
}
