syntax = "proto3";

package currency;

option go_package = "./proto;currency";

service Currency {
	rpc Codes(CodesRequest) returns (CodesResponse) {}
	rpc Rates(RatesRequest) returns (RatesResponse) {}
	rpc Convert(ConvertRequest) returns (ConvertResponse) {}
	rpc History(HistoryRequest) returns (HistoryResponse) {}
}

message Code {
	// e.g USD
	string name = 1;
	// e.g United States Dollar
	string currency = 2;
}

// Codes returns the supported currency codes for the API
message CodesRequest {}

message CodesResponse {
	repeated Code codes = 1;
}

// Returns the historic rates for a currency on a given date
message HistoryRequest {
	// currency code e.g USD
	string code = 1;
	// date formatted as YYYY-MM-DD
	string date = 2;
}

message HistoryResponse {
	// The code of the request
	string code = 1;
	// The date requested
	string date = 2;
	// The rate for the day as code:rate
	map<string, double> rates = 3;
}

// Rates returns the currency rates for a given code e.g USD
message RatesRequest {
	// The currency code to get rates for e.g USD
	string code = 1;
}

message RatesResponse {
	// The code requested e.g USD
	string code = 1;
	// The rates for the given code as key-value pairs code:rate
	map<string, double> rates = 2;
}

// Convert returns the currency conversion rate between two pairs e.g USD/GBP
message ConvertRequest {
	// base code to convert from e.g USD
	string from = 1;
	// target code to convert to e.g GBP
	string to = 2;
	// optional amount to convert e.g 10.0
	double amount = 3;
}

message ConvertResponse {
	// the base code e.g USD
	string from = 1;
	// the target code e.g GBP
	string to = 2;
	// conversion rate e.g 0.71
	double rate = 3;
	// converted amount e.g 7.10
	double amount = 4;
}
