syntax = "proto3";

package fetch.oef.pb;

message StrIntPair {
    string first = 1;
    int32 second = 2;
}

message StrFloatPair {
    string first = 1;
    double second = 2;
}

message StrStrPair {
    string first = 1;
    string second = 2;
}

message TACController {

    message Registered {
    }
    message Unregistered {
    }
    message Cancelled {
    }

    message GameData {
        repeated StrIntPair amount_by_currency_id = 1;
        repeated StrFloatPair exchange_params_by_currency_id = 2;
        repeated StrIntPair quantities_by_good_id = 3;
        repeated StrFloatPair utility_params_by_good_id = 4;
        int64 tx_fee = 5;
        repeated StrStrPair agent_addr_to_name = 6;
        repeated StrStrPair good_id_to_name = 7;
        string version_id = 8;
    }

    message TransactionConfirmation {
        string tx_id = 1;
        repeated StrIntPair amount_by_currency_id = 2;
        repeated StrIntPair quantities_by_good_id = 3;
    }

    message StateUpdate {
        GameData game_data = 1;
        repeated TACAgent.Transaction txs = 2;
    }

    message Error {
        enum ErrorCode {
            GENERIC_ERROR = 0;
            REQUEST_NOT_VALID = 1;
            AGENT_ADDR_ALREADY_REGISTERED = 2;
            AGENT_NAME_ALREADY_REGISTERED = 3;
            AGENT_NOT_REGISTERED = 4;
            TRANSACTION_NOT_VALID = 5;
            TRANSACTION_NOT_MATCHING = 6;
            AGENT_NAME_NOT_IN_WHITELIST = 7;
            COMPETITION_NOT_RUNNING = 8;
            DIALOGUE_INCONSISTENT = 9;
        }

        ErrorCode error_code = 1;
        repeated StrStrPair info = 2;
    }

}

message TACAgent {

    message Register {
        string agent_name = 1;
    }
    message Unregister {
    }

    message Transaction {
        string tx_id = 1;
        string tx_sender_addr = 2;
        string tx_counterparty_addr = 3;
        repeated StrIntPair amount_by_currency_id = 4;
        int64 tx_sender_fee = 5;
        int64 tx_counterparty_fee = 6;
        repeated StrIntPair quantities_by_good_id = 7;
        int64 tx_nonce = 8;
        bytes tx_sender_signature = 9;
        bytes tx_counterparty_signature = 10;
    }

    message GetStateUpdate {
    }

}

message TACMessage {
    oneof content{
        TACAgent.Register register = 1;
        TACAgent.Unregister unregister = 2;
        TACAgent.Transaction transaction = 3;
        TACAgent.GetStateUpdate get_state_update = 4;
        TACController.Registered registered = 5;
        TACController.Unregistered unregistered = 6;
        TACController.Cancelled cancelled = 7;
        TACController.GameData game_data = 8;
        TACController.TransactionConfirmation transaction_confirmation = 9;
        TACController.StateUpdate state_update = 10;
        TACController.Error error = 11;
    }
}
