syntax = "proto3";

package yandex.cloud.mdb.mongodb.v1;

import "google/protobuf/timestamp.proto";
import "google/protobuf/wrappers.proto";
import "google/type/timeofday.proto";
import "yandex/cloud/mdb/mongodb/v1/config/mongodb3_6.proto";
import "yandex/cloud/mdb/mongodb/v1/config/mongodb4_0.proto";
import "yandex/cloud/mdb/mongodb/v1/config/mongodb4_2.proto";
import "yandex/cloud/mdb/mongodb/v1/config/mongodb4_4.proto";
import "yandex/cloud/mdb/mongodb/v1/maintenance.proto";

option go_package = "github.com/yandex-cloud/go-genproto/yandex/cloud/mdb/mongodb/v1;mongodb";
option java_package = "yandex.cloud.api.mdb.mongodb.v1";

// A managed MongoDB cluster. For more information, see the [documentation](/docs/managed-mongodb/concepts).
message Cluster {
  // Deployment environment.
  enum Environment {
    ENVIRONMENT_UNSPECIFIED = 0;

    // Stable environment with a conservative update policy: only hotfixes
    // are applied during regular maintenance.
    PRODUCTION = 1;

    // Environment with more aggressive update policy: new versions
    // are rolled out irrespective of backward compatibility.
    PRESTABLE = 2;
  }

  enum Health {

    // State of the cluster is unknown ([Host.health] for every host in the cluster is UNKNOWN).
    HEALTH_UNKNOWN = 0;

    // Cluster is alive and well ([Host.health] for every host in the cluster is ALIVE).
    ALIVE = 1;

    // Cluster is inoperable ([Host.health] for every host in the cluster is DEAD).
    DEAD = 2;

    // Cluster is working below capacity ([Host.health] for at least one host in the cluster is not ALIVE).
    DEGRADED = 3;
  }

  enum Status {

    // Cluster state is unknown.
    STATUS_UNKNOWN = 0;

    // Cluster is being created.
    CREATING = 1;

    // Cluster is running normally.
    RUNNING = 2;

    // Cluster encountered a problem and cannot operate.
    ERROR = 3;

    // Cluster is being updated.
    UPDATING = 4;

    // Cluster is stopping.
    STOPPING = 5;

    // Cluster stopped.
    STOPPED = 6;

    // Cluster is starting.
    STARTING = 7;
  }

  // ID of the MongoDB cluster.
  // This ID is assigned by MDB at creation time.
  string id = 1;

  // ID of the folder that the MongoDB cluster belongs to.
  string folder_id = 2;

  // Creation timestamp in [RFC3339](https://www.ietf.org/rfc/rfc3339.txt) text format.
  google.protobuf.Timestamp created_at = 3;

  // Name of the MongoDB cluster.
  // The name is unique within the folder. 1-63 characters long.
  string name = 4;

  // Description of the MongoDB cluster. 0-256 characters long.
  string description = 5;

  // Custom labels for the MongoDB cluster as `` key:value `` pairs. Maximum 64 per resource.
  map<string, string> labels = 6;

  // Deployment environment of the MongoDB cluster.
  Environment environment = 7;

  // Description of monitoring systems relevant to the MongoDB cluster.
  repeated Monitoring monitoring = 8;

  // Configuration of the MongoDB cluster.
  ClusterConfig config = 9;

  // ID of the network that the cluster belongs to.
  string network_id = 10;

  // Aggregated cluster health.
  Health health = 11;

  // Current state of the cluster.
  Status status = 12;

  // Indicates current sharding status of the cluster.
  bool sharded = 13;

  // Maintenance window for the cluster.
  MaintenanceWindow maintenance_window = 14;

  // Planned maintenance operation to be started for the cluster within the nearest [maintenance_window].
  MaintenanceOperation planned_operation = 15;

  // User security groups
  repeated string security_group_ids = 16;

  // Deletion Protection inhibits deletion of the cluster
  bool deletion_protection = 17;
}

// Monitoring system.
message Monitoring {
  // Name of the monitoring system.
  string name = 1;

  // Description of the monitoring system.
  string description = 2;

  // Link to the monitoring system charts for the MongoDB cluster.
  string link = 3;
}

message ClusterConfig {
  // Version of MongoDB server software. Possible values: `3.6`, `4.0`, `4.2`, `4.4`.
  string version = 1;

  // MongoDB feature compatibility version. See usage details in [MongoDB documentation](https://docs.mongodb.com/manual/reference/command/setFeatureCompatibilityVersion/).
  //
  // Possible values:
  // * `3.6` - persist data compatibility for version 3.6. After setting this option the data will not be compatible with 3.4 or lower.
  // * `4.0` - persist data compatibility for version 4.0. After setting this option the data will not be compatible with 3.6 or lower.
  // * `4.2` - persist data compatibility for version 4.2. After setting this option the data will not be compatible with 4.0 or lower.
  // * `4.4` - persist data compatibility for version 4.4. After setting this option the data will not be compatible with 4.2 or lower.
  string feature_compatibility_version = 5;

  // Configuration for MongoDB servers in the cluster.
  oneof mongodb {
    // Configuration and resource allocation for a MongoDB 3.6 cluster.
    Mongodb3_6 mongodb_3_6 = 2 [json_name="mongodb_3_6"];

    // Configuration and resource allocation for a MongoDB 4.0 cluster.
    Mongodb4_0 mongodb_4_0 = 4 [json_name="mongodb_4_0"];

    // Configuration and resource allocation for a MongoDB 4.2 cluster.
    Mongodb4_2 mongodb_4_2 = 7 [json_name="mongodb_4_2"];

    // Configuration and resource allocation for a MongoDB 4.4 cluster.
    Mongodb4_4 mongodb_4_4 = 8 [json_name="mongodb_4_4"];
  }

  // Time to start the daily backup, in the UTC timezone.
  google.type.TimeOfDay backup_window_start = 3;

  // Retain period of automatically created backup in days
  google.protobuf.Int64Value backup_retain_period_days = 9;

  // Access policy to DB
  Access access = 6;
}

message Mongodb3_6 {
  message Mongod {
    // Configuration for a mongod 3.6 hosts.
    config.MongodConfigSet3_6 config = 1;

    // Resources allocated to MongoDB hosts.
    Resources resources = 2;
  }

  message MongoCfg {
    config.MongoCfgConfigSet3_6 config = 1;

    // Resources allocated to mongocfg hosts.
    Resources resources = 2;
  }

  message Mongos {
    config.MongosConfigSet3_6 config = 1;

    // Resources allocated to mongocfg hosts.
    Resources resources = 2;
  }

  message MongoInfra {
    config.MongosConfigSet3_6 config_mongos = 1;
    config.MongoCfgConfigSet3_6 config_mongocfg = 2;

    // Resources allocated to mongoinfra (mongos+mongocfg) hosts.
    Resources resources = 3;
  }


  // Configuration and resource allocation for mongod in a MongoDB 3.6 cluster.
  Mongod mongod = 1;

  // Configuration and resource allocation for mongocfg in a MongoDB 3.6 cluster.
  MongoCfg mongocfg = 2;

  // Configuration and resource allocation for mongos in a MongoDB 3.6 cluster.
  Mongos mongos = 3;

  // Configuration and resource allocation for mongoinfra (mongos+mongocfg) in a MongoDB 3.6 cluster.
  MongoInfra mongoinfra = 4;
}

message Mongodb4_0 {
  message Mongod {
    // Configuration for mongod 4.0 hosts.
    config.MongodConfigSet4_0 config = 1;

    // Resources allocated to mongod hosts.
    Resources resources = 2;
  }

  message MongoCfg {
    // Configuration for mongocfg 4.0 hosts.
    config.MongoCfgConfigSet4_0 config = 1;

    // Resources allocated to mongocfg hosts.
    Resources resources = 2;
  }

  message Mongos {
    // Configuration for mongos 4.0 hosts.
    config.MongosConfigSet4_0 config = 1;

    // Resources allocated to mongos hosts.
    Resources resources = 2;
  }

  message MongoInfra {
    config.MongosConfigSet4_0 config_mongos = 1;
    config.MongoCfgConfigSet4_0 config_mongocfg = 2;

    // Resources allocated to mongoinfra (mongos+mongocfg) hosts.
    Resources resources = 3;
  }

  // Configuration and resource allocation for mongod in a MongoDB 4.0 cluster.
  Mongod mongod = 1;

  // Configuration and resource allocation for mongocfg in a MongoDB 4.0 cluster.
  MongoCfg mongocfg = 2;

  // Configuration and resource allocation for mongos in a MongoDB 4.0 cluster.
  Mongos mongos = 3;

  // Configuration and resource allocation for mongoinfra (mongos+mongocfg) in a MongoDB 4.0 cluster.
  MongoInfra mongoinfra = 4;
}

message Mongodb4_2 {
  message Mongod {
    // Configuration for mongod 4.2 hosts.
    config.MongodConfigSet4_2 config = 1;

    // Resources allocated to mongod hosts.
    Resources resources = 2;
  }

  message MongoCfg {
    // Configuration for mongocfg 4.2 hosts.
    config.MongoCfgConfigSet4_2 config = 1;

    // Resources allocated to mongocfg hosts.
    Resources resources = 2;
  }

  message Mongos {
    // Configuration for mongos 4.2 hosts.
    config.MongosConfigSet4_2 config = 1;

    // Resources allocated to mongos hosts.
    Resources resources = 2;
  }

  message MongoInfra {
    config.MongosConfigSet4_2 config_mongos = 1;
    config.MongoCfgConfigSet4_2 config_mongocfg = 2;

    // Resources allocated to mongoinfra (mongos+mongocfg) hosts.
    Resources resources = 3;
  }

  // Configuration and resource allocation for mongod in a MongoDB 4.2 cluster.
  Mongod mongod = 1;

  // Configuration and resource allocation for mongocfg in a MongoDB 4.2 cluster.
  MongoCfg mongocfg = 2;

  // Configuration and resource allocation for mongos in a MongoDB 4.2 cluster.
  Mongos mongos = 3;

  // Configuration and resource allocation for mongoinfra (mongos+mongocfg) in a MongoDB 4.2 cluster.
  MongoInfra mongoinfra = 4;
}

message Mongodb4_4 {
  message Mongod {
    // Configuration for mongod 4.4 hosts.
    config.MongodConfigSet4_4 config = 1;

    // Resources allocated to mongod hosts.
    Resources resources = 2;
  }

  message MongoCfg {
    // Configuration for mongocfg 4.4 hosts.
    config.MongoCfgConfigSet4_4 config = 1;

    // Resources allocated to mongocfg hosts.
    Resources resources = 2;
  }

  message Mongos {
    // Configuration for mongos 4.4 hosts.
    config.MongosConfigSet4_4 config = 1;

    // Resources allocated to mongos hosts.
    Resources resources = 2;
  }

  message MongoInfra {
    config.MongosConfigSet4_4 config_mongos = 1;
    config.MongoCfgConfigSet4_4 config_mongocfg = 2;

    // Resources allocated to mongoinfra (mongos+mongocfg) hosts.
    Resources resources = 3;
  }

  // Configuration and resource allocation for mongod in a MongoDB 4.4 cluster.
  Mongod mongod = 1;

  // Configuration and resource allocation for mongocfg in a MongoDB 4.4 cluster.
  MongoCfg mongocfg = 2;

  // Configuration and resource allocation for mongos in a MongoDB 4.4 cluster.
  Mongos mongos = 3;

  // Configuration and resource allocation for mongoinfra (mongos+mongocfg) in a MongoDB 4.4 cluster.
  MongoInfra mongoinfra = 4;
}

message Shard {
  // Name of the shard.
  string name = 1;

  // ID of the cluster that the shard belongs to.
  string cluster_id = 2;
}

message Host {
  enum Type {
    TYPE_UNSPECIFIED = 0;

    // A mongod host.
    MONGOD = 1;

    // A mongos host.
    MONGOS = 2;

    // A mongocfg host.
    MONGOCFG = 3;

    // A mongoinfra (mongos+mongocfg) host.
    MONGOINFRA = 4;
  }

  enum Role {

    // Role of the host in the cluster is unknown.
    ROLE_UNKNOWN = 0;

    // Host is the primary MongoDB server in the cluster.
    PRIMARY = 1;

    // Host is a secondary MongoDB server in the cluster.
    SECONDARY = 2;
  }

  enum Health {

    // Health of the host is unknown.
    HEALTH_UNKNOWN = 0;

    // The host is performing all its functions normally.
    ALIVE = 1;

    // The host is inoperable, and cannot perform any of its essential functions.
    DEAD = 2;

    // The host is degraded, and can perform only some of its essential functions.
    DEGRADED = 3;
  }

  // Name of the MongoDB host. The host name is assigned by MDB at creation time, and cannot be changed.
  // 1-63 characters long.
  //
  // The name is unique across all existing MDB hosts in Yandex.Cloud, as it defines the FQDN of the host.
  string name = 1;

  // ID of the MongoDB host. The ID is assigned by MDB at creation time.
  string cluster_id = 2;

  // ID of the availability zone where the MongoDB host resides.
  string zone_id = 3;

  // Resources allocated to the MongoDB host.
  Resources resources = 4;

  // Role of the host in the cluster.
  Role role = 5;

  // Status code of the aggregated health of the host.
  Health health = 6;

  // Services provided by the host.
  repeated Service services = 7;

  // ID of the subnet that the host belongs to.
  string subnet_id = 8;

  // Flag showing public IP assignment status to this host.
  bool assign_public_ip = 9;

  // Shard which this host belongs to.
  string shard_name = 10;

  // Host type
  Type type = 11;
}

message Service {
  enum Type {
    TYPE_UNSPECIFIED = 0;

    // The host is running a mongod daemon.
    MONGOD = 1;

    // The host is running a mongos daemon.
    MONGOS = 2;

    // The host is running a MongoDB config server.
    MONGOCFG = 3;
  }

  enum Health {

    // Health of the server is unknown.
    HEALTH_UNKNOWN = 0;

    // The server is working normally.
    ALIVE = 1;

    // The server is dead or unresponsive.
    DEAD = 2;
  }

  // Type of the service provided by the host.
  Type type = 1;

  // Status code of server availability.
  Health health = 2;
}

message Resources {
  // ID of the preset for computational resources available to a host (CPU, memory etc.).
  // All available presets are listed in the [documentation](/docs/managed-mongodb/concepts/instance-types).
  string resource_preset_id = 1;

  // Volume of the storage available to a host, in bytes.
  int64 disk_size = 2;

  // Type of the storage environment for the host.
  // Possible values:
  // * network-hdd - network HDD drive,
  // * network-ssd - network SSD drive,
  // * local-ssd - local SSD storage.
  string disk_type_id = 3;
}

message Access {
  // Allow access for DataLens
  bool data_lens = 1;
}
