// Copyright 2026 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

syntax = "proto3";

package google.cloud.databasecenter.v1beta;

import "google/api/field_behavior.proto";
import "google/protobuf/timestamp.proto";
import "google/type/date.proto";
import "google/type/dayofweek.proto";
import "google/type/timeofday.proto";

option csharp_namespace = "Google.Cloud.DatabaseCenter.V1Beta";
option go_package = "cloud.google.com/go/databasecenter/apiv1beta/databasecenterpb;databasecenterpb";
option java_multiple_files = true;
option java_outer_classname = "MaintenanceProto";
option java_package = "com.google.cloud.databasecenter.v1beta";
option php_namespace = "Google\\Cloud\\DatabaseCenter\\V1beta";
option ruby_package = "Google::Cloud::DatabaseCenter::V1beta";

// Phase/Week of the maintenance window. This is to capture order of
// maintenance. For example, for Cloud SQL resources -
// https://cloud.google.com/sql/docs/mysql/maintenance.
// This enum can be extended to support DB Center specific phases for
// recommendation plan generation.
enum Phase {
  // Phase is unspecified.
  PHASE_UNSPECIFIED = 0;

  // Week 1.
  PHASE_WEEK1 = 1;

  // Week 2.
  PHASE_WEEK2 = 2;

  // Week 5.
  PHASE_WEEK5 = 3;

  // Any phase.
  PHASE_ANY = 4;
}

// Resource maintenance state.
enum MaintenanceState {
  // Status is unspecified.
  MAINTENANCE_STATE_UNSPECIFIED = 0;

  // Maintenance is scheduled.
  MAINTENANCE_STATE_SCHEDULED = 1;

  // Maintenance is in progress.
  MAINTENANCE_STATE_IN_PROGRESS = 2;

  // Maintenance is completed.
  MAINTENANCE_STATE_COMPLETED = 3;

  // Maintenance has failed.
  MAINTENANCE_STATE_FAILED = 4;
}

// Possible reasons why the maintenance is not completed.
// STATE_FAILED maintenance state may not always have a failure reason.
enum PossibleFailureReason {
  // Failure reason is unspecified.
  POSSIBLE_FAILURE_REASON_UNSPECIFIED = 0;

  // Maintenance may not be completed because there is a deny policy
  // overlapping with upcoming maintenance schedule.
  POSSIBLE_FAILURE_REASON_DENY_POLICY_CONFLICT = 1;

  // Maintenance may not be completed because the instance is stopped.
  POSSIBLE_FAILURE_REASON_INSTANCE_IN_STOPPED_STATE = 2;
}

// Maintenance window for the database resource. It specifies preferred time
// and day of the week and phase in some cases, when the maintenance can start.
message ResourceMaintenanceSchedule {
  // Optional. Preferred time to start the maintenance operation on the
  // specified day.
  google.type.TimeOfDay start_time = 1 [(google.api.field_behavior) = OPTIONAL];

  // Optional. Preferred day of the week for maintenance, e.g. MONDAY, TUESDAY,
  // etc.
  google.type.DayOfWeek day = 2 [(google.api.field_behavior) = OPTIONAL];

  // Optional. Phase of the maintenance window. This is to capture order of
  // maintenance. For example, for Cloud SQL resources, this can be used to
  // capture if the maintenance window is in Week1, Week2, Week5, etc. Non
  // production resources are usually part of early phase.
  // For more details, refer to Cloud SQL resources -
  // https://cloud.google.com/sql/docs/mysql/maintenance
  Phase phase = 3 [(google.api.field_behavior) = OPTIONAL];
}

// Deny maintenance period for the database resource. It specifies the time
// range during which the maintenance cannot start. This is configured by the
// customer.
message ResourceMaintenanceDenySchedule {
  // Optional. The start date of the deny maintenance period.
  google.type.Date start_date = 1 [(google.api.field_behavior) = OPTIONAL];

  // Optional. Deny period end date.
  google.type.Date end_date = 2 [(google.api.field_behavior) = OPTIONAL];

  // Optional. Time in UTC when the deny period starts on start_date and ends on
  // end_date.
  google.type.TimeOfDay time = 3 [(google.api.field_behavior) = OPTIONAL];
}

// Upcoming maintenance window for the database resource.
message UpcomingMaintenance {
  // Output only. Start time of the upcoming maintenance.
  // Start time is always populated when an upcoming maintenance is
  // scheduled.
  google.protobuf.Timestamp start_time = 1
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. End time of the upcoming maintenance. This is only populated
  // for an engine, if end time is public for the engine.
  google.protobuf.Timestamp end_time = 2
      [(google.api.field_behavior) = OUTPUT_ONLY];
}

// MaintenanceInfo to capture the maintenance details of database resource.
message MaintenanceInfo {
  // Optional. Maintenance window for the database resource.
  ResourceMaintenanceSchedule maintenance_schedule = 1
      [(google.api.field_behavior) = OPTIONAL];

  // Optional. List of Deny maintenance period for the database resource.
  repeated ResourceMaintenanceDenySchedule deny_maintenance_schedules = 2
      [(google.api.field_behavior) = OPTIONAL];

  // Output only. Current Maintenance version of the database resource. Example:
  // "MYSQL_8_0_41.R20250531.01_15"
  string maintenance_version = 3 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The date when the maintenance version was released.
  google.type.Date current_version_release_date = 4
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. Upcoming maintenance window for the database resource. This is
  // only populated for an engine, if upcoming maintenance is scheduled for the
  // resource. This schedule is generated per engine and engine version, and
  // there is only one upcoming maintenance window at any given time. In case of
  // upcoming maintenance, the maintenance_state will be set to SCHEDULED first,
  // and then IN_PROGRESS when the maintenance window starts.
  UpcomingMaintenance upcoming_maintenance = 5
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. Resource maintenance state. This is to capture the current
  // state of the maintenance.
  MaintenanceState state = 6 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. List of possible reasons why the maintenance is not completed.
  // This is an optional field and is only populated if there are any
  // reasons for failures recorded for the maintenance by DB Center.
  // FAILURE maintenance status may not always have a failure reason.
  repeated PossibleFailureReason possible_failure_reasons = 7
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. Previous maintenance version of the database resource.
  // Example: "MYSQL_8_0_41.R20250531.01_15". This is available once a minor
  // version maintenance is complete on a database resource.
  string previous_maintenance_version = 8
      [(google.api.field_behavior) = OUTPUT_ONLY];
}
