# Copyright (C) 2018-present MongoDB, Inc.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the Server Side Public License, version 1,
# as published by MongoDB, Inc.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# Server Side Public License for more details.
#
# You should have received a copy of the Server Side Public License
# along with this program. If not, see
# <http://www.mongodb.com/licensing/server-side-public-license>.
#
# As a special exception, the copyright holders give permission to link the
# code of portions of this program with the OpenSSL library under certain
# conditions as described in each individual source file and distribute
# linked combinations including the program with the OpenSSL library. You
# must comply with the Server Side Public License in all respects for
# all of the code used other than as permitted herein. If you modify file(s)
# with this exception, you may extend this exception to your version of the
# file(s), but you are not obligated to do so. If you do not wish to do so,
# delete this exception statement from your version. If you delete this
# exception statement from all source files in the program, then also delete
# it in the license file.
#

global:
    cpp_namespace: "mongo::txn"
    cpp_includes:
        - "mongo/db/s/transaction_coordinator_structures.h"

imports:
    - "mongo/idl/basic_types.idl"
    - "mongo/db/logical_session_id.idl"
    - "mongo/s/sharding_types.idl"

types:
    commit_decision_enum:
        bson_serialization_type: string
        description: "Ensures that the commit decision serializes/deserializes to a fixed set of
                      string values"
        cpp_type: "txn::CommitDecision"
        serializer: "::mongo::txn::writeCommitDecisionEnumProperty"
        deserializer: "::mongo::txn::readCommitDecisionEnumProperty"

    status:
        bson_serialization_type: any
        description: "Serializes/deserializes the general server Status type"
        cpp_type: "::mongo::Status"
        serializer: "::mongo::txn::writeStatusProperty"
        deserializer: "::mongo::txn::readStatusProperty"

structs:
    CoordinatorCommitDecision:
        description: "An object representing the coordinator's commit decision."
        strict: true
        fields:
            decision:
                type: commit_decision_enum
                description: "See the values in txn::CommitDecision for details. Can only be commit
                              or abort."
            commitTimestamp:
                optional: true
                type: timestamp
                description: "If the decision is 'commit', contains the chosen commit timestamp,
                              otherwise it will not be set"
            abortStatus:
                optional: true
                type: status
                description: "If the decision is 'abort', contains the reason the shard aborted,
                              otherwise it will not be set"

    TransactionCoordinatorDocument:
        description: "A document used for majority confirming the coordinator's state changes"
        strict: true
        fields:
            _id:
                type: OperationSessionInfo
                description: "The sessionId and txnNumber of this transaction."
                cpp_name: id
            participants:
                type: array<shard_id>
                description: "The list of transaction participants."
            decision:
                optional: true
                type: CoordinatorCommitDecision
                description: "The coordinator's decision for the transaction including the decision
                              ('commit' or 'abort') and a commit timestamp (if the decision is
                              'commit'). Only set if the coordinator has made a decision."
