syntax = "proto3";

package api;

option go_package = "github.com/psviderski/uncloud/internal/machine/api/pb";

import "google/protobuf/empty.proto";
import "internal/machine/api/pb/common.proto";
import "internal/machine/api/pb/machine.proto";

service Cluster {
  rpc AddMachine(AddMachineRequest) returns (AddMachineResponse);
  rpc ListMachines(google.protobuf.Empty) returns (ListMachinesResponse);
  rpc UpdateMachine(UpdateMachineRequest) returns (UpdateMachineResponse);
  rpc RemoveMachine(RemoveMachineRequest) returns (google.protobuf.Empty);

  rpc ReserveDomain(ReserveDomainRequest) returns (Domain);
  rpc GetDomain(google.protobuf.Empty) returns (Domain);
  rpc ReleaseDomain(google.protobuf.Empty) returns (Domain);
  rpc CreateDomainRecords(CreateDomainRecordsRequest) returns (CreateDomainRecordsResponse);
}

message AddMachineRequest {
  string name = 1;
  NetworkConfig network = 2;
  IP public_ip = 3;
}

message AddMachineResponse {
  MachineInfo machine = 1;
}

message MachineMember {
  MachineInfo machine = 1;

  enum MembershipState {
    UNKNOWN = 0;
    // The member is active.
    UP = 1;
    // The member is active, but at least one cluster member suspects its down. For all purposes,
    // a SUSPECT member is treated as if it were UP until either it refutes the suspicion (becoming UP)
    // or fails to do so (being declared DOWN).
    SUSPECT = 2;
    // The member is confirmed DOWN.
    DOWN = 3;
  }
  MembershipState state = 2;
}

message ListMachinesResponse {
  repeated MachineMember machines = 1;
}

message UpdateMachineRequest {
  // Machine to update
  string machine_id = 1;

  // Updated machine information
  optional string name = 2;
  optional IP public_ip = 3;
  repeated IPPort endpoints = 4;
}

message UpdateMachineResponse {
  MachineInfo machine = 1;
}

message RemoveMachineRequest {
  string id = 1;
}

message Domain {
  string name = 1;
}

message ReserveDomainRequest {
  string endpoint = 1;
}

message CreateDomainRecordsRequest {
  repeated DNSRecord records = 1;
}

message CreateDomainRecordsResponse {
  repeated DNSRecord records = 1;
}

message DNSRecord {
  string name = 1;

  enum RecordType {
    UNSPECIFIED = 0;
    A = 1;
    AAAA = 2;
  }
  RecordType type = 2;
  repeated string values = 3;
}
