syntax = "proto3";

package global.nextgen.v1;

import "global/common/v1/service_plan.proto";
import "google/api/field_behavior.proto";
import "google/protobuf/timestamp.proto";

message Backup {
  // TriggerType enum for backup operations
  enum TriggerType {
    TRIGGER_TYPE_UNSPECIFIED = 0;
    TRIGGER_TYPE_AUTO = 1;
    TRIGGER_TYPE_MANUAL = 2;
  }

  // State enum for backup operations
  enum State {
    STATE_UNSPECIFIED = 0;
    STATE_UNKNOWN = 1;
    STATE_PENDING = 2;
    STATE_RUNNING = 3;
    STATE_SUCCESS = 4;
    STATE_FAILED = 5;
    STATE_CANCELLED = 6;
  }

  // Type enum for backup operations
  enum Type {
    TYPE_UNSPECIFIED = 0;
    TYPE_SNAPSHOT = 1;
    TYPE_COPIED = 2;
  }

  // The unique identifier of the backup
  string id = 1 [(google.api.field_behavior) = OUTPUT_ONLY];

  // The ID of the TiDB cluster this backup belongs to
  string cluster_id = 2 [(google.api.field_behavior) = OUTPUT_ONLY];

  // The ID of the Tenant this backup belongs to
  string organization_id = 3 [(google.api.field_behavior) = OUTPUT_ONLY];

  // The service plan of the backup
  common.v1.ServicePlan service_plan = 4 [(google.api.field_behavior) = OUTPUT_ONLY];

  // The name of the backup
  string display_name = 5 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Description of the backup
  string description = 6 [(google.api.field_behavior) = OPTIONAL];

  // Timestamp when the backup was created
  google.protobuf.Timestamp create_time = 7 [(google.api.field_behavior) = OUTPUT_ONLY];

  // The size of the backup in bytes
  int64 size = 8 [(google.api.field_behavior) = OUTPUT_ONLY];

  // The state of the backup
  State state = 9 [(google.api.field_behavior) = OUTPUT_ONLY];

  // The type of backup (snapshot / copied backup)
  Type type = 10 [(google.api.field_behavior) = OUTPUT_ONLY];

  // The trigger type of the backup
  TriggerType trigger_type = 11 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Timestamp when the backup expires
  google.protobuf.Timestamp expiration_time = 12 [(google.api.field_behavior) = OUTPUT_ONLY];

  // The backup tso
  string backup_ts = 13 [(google.api.field_behavior) = OUTPUT_ONLY];

  // The region ID where the backup is stored
  string region_id = 14 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Whether the source cluster used a customer-managed key at backup time.
  // Combine with `encryption_key_id`:
  // - `encryption_key_id == 0`: backup was not encrypted
  // - `encryption_key_id != 0 && customer_managed == false`: backup used SMEK
  // - `encryption_key_id != 0 && customer_managed == true`: backup used CMEK
  bool customer_managed = 15 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Source cluster encryption key ID at backup time. `0` means no encryption key was used.
  uint64 encryption_key_id = 16 [(google.api.field_behavior) = OUTPUT_ONLY];
}

message BackupSetting {
  enum BackupMode {
    BACKUP_MODE_UNSPECIFIED = 0;
    STANDARD_BUNDLE = 1;
    FLEXIBLE_RETENTION = 2;
  }
  // keep definition same as openapi
  message BackupPolicy {
    enum Tier {
      TIER_UNSPECIFIED = 0;
      TIER1 = 1;
      TIER2 = 2;
      TIER3 = 3;
    }
    message PiTRPolicy {
      int32 retention_days = 1;
    }
    message HourlyPolicy {
      int32 retention_days = 1;
    }
    message DailyPolicy {
      int32 retention_days = 1;
      string start_time_utc = 2;
    }
    Tier name = 1 [(google.api.field_behavior) = OUTPUT_ONLY];
    string description = 2 [(google.api.field_behavior) = OUTPUT_ONLY];
    PiTRPolicy pitr = 3 [(google.api.field_behavior) = OUTPUT_ONLY];
    HourlyPolicy hourly_backup = 4 [(google.api.field_behavior) = OUTPUT_ONLY];
    DailyPolicy daily_backup = 5 [(google.api.field_behavior) = OUTPUT_ONLY];
  }

  string cluster_id = 1 [(google.api.field_behavior) = REQUIRED];
  BackupPolicy.Tier backup_policy = 2 [
    deprecated = true,
    (google.api.field_behavior) = OPTIONAL
  ];
  google.protobuf.Timestamp pitr_start_time = 3 [(google.api.field_behavior) = OUTPUT_ONLY];
  google.protobuf.Timestamp pitr_end_time = 4 [(google.api.field_behavior) = OUTPUT_ONLY];
  google.protobuf.Timestamp delete_time = 5 [(google.api.field_behavior) = OUTPUT_ONLY];
  google.protobuf.Timestamp last_modify_time = 6 [(google.api.field_behavior) = OUTPUT_ONLY];
  BackupMode mode = 7 [(google.api.field_behavior) = OPTIONAL];
  optional int32 retention_days = 8 [(google.api.field_behavior) = OPTIONAL];
  optional string daily_backup_time_utc = 9 [(google.api.field_behavior) = OPTIONAL];
}
