# Copyright (C) 2020-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.
#

# This file must be separate from repl_set_config.idl to avoid circular includes between
# member_config.h and repl_set_config_gen.h

global:
    cpp_namespace: "mongo::repl"
    cpp_includes:
        - "mongo/db/repl/member_id.h"
        - "mongo/db/repl/repl_set_config_validators.h"


imports:
    - "mongo/idl/basic_types.idl"

types:
    memberId:
        bson_serialization_type: any
        description: A wrapper around an integer for the MemberId of a MemberConfig.
        cpp_type: "MemberId"
        serializer: MemberId::serializeToBSON
        deserializer: MemberId::parseFromBSON

    memberConfig:
        bson_serialization_type: object
        description: "A single member in the replica set configuration"
        cpp_type: MemberConfig
        serializer: MemberConfig::toBSON
        deserializer: MemberConfig::parseFromBSON

structs:
    MemberConfigBase:
        description: "The configuration for a given member inside of the replica set config"
        fields:
            _id:
                cpp_name: id
                type: memberId
                description: "An integer identifier of every member in the replica set"
            host:
                type: string
                description: "The hostname and, if specified, the port number, of the set member"
            votes:
                type: safeInt64
                default: 1
                validator: { gte: 0, lte: 1 }
                description: "The number of votes a server will cast in a replica set election. The
                              number of votes each member has is either 1 or 0, and arbiters always
                              have exactly 1 vote"
            newlyAdded:
                type: bool
                optional: true
                validator: { callback: "validateTrue" }
                description: "Set to true if the member was just added and is in initial sync.
                              Must be true when specified. Indicates that the votes and priority
                              fields should be considered '0' for the duration of the initial sync"
            priority:
                type: safeDouble
                default: 1.0
                validator: { gte: 0, lte: 1000 }
                description: "A number that indicates the relative eligibility of a member to become
                              a primary"
            hidden:
                type: safeBool
                default: false
                description: "When this value is true, the replica set hides this instance and does
                             not include the member in the output of db.hello() or hello. This
                             prevents read operations (i.e. queries) from ever reaching this host by
                             way of secondary read preference"

            secondaryDelaySecs:
                cpp_name: secondaryDelaySecs
                type: safeInt64
                optional: true
                validator: { gte: 0, lte: 31622400 }
                description: "The number of seconds 'behind' the primary that this replica set
                              member should 'lag'."
            arbiterOnly:
                type: safeBool
                default: false
                description: "A boolean that identifies an arbiter. A value of true indicates that
                              the member is an arbiter"
            buildIndexes:
                type: safeBool
                default: true
                description: "A boolean that indicates whether the mongod builds indexes on this
                              member"
            tags:
                type: object_owned
                optional: true
                description: "A tags document contains user-defined tag field and value pairs for
                              the replica set member"
            horizons:
                type: object
                optional: true
                description: "The hostnames for the provided horizons"
