// 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.chat.v1;

import "google/api/field_behavior.proto";
import "google/api/resource.proto";
import "google/chat/v1/reaction.proto";
import "google/protobuf/duration.proto";
import "google/protobuf/field_mask.proto";
import "google/protobuf/timestamp.proto";

option csharp_namespace = "Google.Apps.Chat.V1";
option go_package = "cloud.google.com/go/chat/apiv1/chatpb;chatpb";
option java_multiple_files = true;
option java_outer_classname = "AvailabilityProto";
option java_package = "com.google.chat.v1";
option objc_class_prefix = "DYNAPIProto";
option php_namespace = "Google\\Apps\\Chat\\V1";
option ruby_package = "Google::Apps::Chat::V1";

// Represents a user's current availability information in Google Chat,
// including their state (for example, Active, Away, Do Not Disturb) and any
// custom status.
message Availability {
  option (google.api.resource) = {
    type: "chat.googleapis.com/Availability"
    pattern: "users/{user}/availability"
    plural: "availabilities"
    singular: "availability"
  };

  // Represents the current availability state of the user.
  enum State {
    // Default value. The state is unspecified.
    STATE_UNSPECIFIED = 0;

    // The user is currently active, based on recent activity.
    ACTIVE = 1;

    // The user is currently idle. This state indicates a period of inactivity
    // after being ACTIVE, before potentially transitioning to AWAY.
    IDLE = 2;

    // The user is currently away. This can be either automatically set after
    // a period of inactivity in ACTIVE or IDLE state, or it can be manually set
    // by the user. When manually set via `MarkAsAway`, this state persists
    // regardless of user activity.
    AWAY = 3;

    // The user is in Do Not Disturb state, which is manually set.
    DO_NOT_DISTURB = 4;
  }

  // Identifier. Resource name of the user's availability.
  //
  // Format: `users/{user}/availability`
  //
  // `{user}` is the id for the Person in the People API or Admin SDK directory
  // API. For example, `users/123456789`.
  //
  // The user's email address or `me` can also be used as an alias to refer to
  // the caller.  For example, `users/user@example.com` or `users/me`.
  string name = 1 [(google.api.field_behavior) = IDENTIFIER];

  // Output only. The user's current availability state.
  State state = 2 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Additional metadata associated with the user's availability state.
  oneof state_metadata {
    // Output only. Metadata if the user state is set to DO_NOT_DISTURB.
    DoNotDisturbMetadata do_not_disturb_metadata = 3
        [(google.api.field_behavior) = OUTPUT_ONLY];
  }

  // Optional. The user's custom status.
  CustomStatus custom_status = 4 [(google.api.field_behavior) = OPTIONAL];
}

// Represents a user's custom status in Google Chat.
// This includes a short text message with an optional emoji that a user sets to
// give more context about their availability.
message CustomStatus {
  // Required. The text of the custom status. This will be a string with maximum
  // length of 64.
  string text = 1 [(google.api.field_behavior) = REQUIRED];

  // Required. The emoji of the custom status. Only Unicode emojis are
  // supported; custom emojis are not supported.
  Emoji emoji = 2 [(google.api.field_behavior) = REQUIRED];

  // The expiration time of the custom status. It can be specified as either
  // an absolute timestamp or a time-to-live duration.
  oneof expiration {
    // The timestamp when the custom status expires.
    google.protobuf.Timestamp expire_time = 3;

    // Input only. The time-to-live duration after which the custom status
    // expires.
    google.protobuf.Duration ttl = 4 [(google.api.field_behavior) = INPUT_ONLY];
  }
}

// Metadata associated with the `DO_NOT_DISTURB` availability state,
// specifying when the state is set to expire.
message DoNotDisturbMetadata {
  // Output only. Timestamp until which the user should be marked as
  // DO_NOT_DISTURB. This can be maximum of 1 year in the future.
  google.protobuf.Timestamp expiration_time = 1
      [(google.api.field_behavior) = OUTPUT_ONLY];
}

// Request message for the `GetAvailability` method.
message GetAvailabilityRequest {
  // Required. The resource name of the availability to retrieve.
  //
  // Format: users/{user}/availability
  //
  // `{user}` is the id for the Person in the People API or Admin SDK directory
  // API. For example, `users/123456789`.
  //
  // The user's email address or `me` can also be used as an alias to refer to
  // the caller.  For example, `users/user@example.com` or `users/me`.
  string name = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "chat.googleapis.com/Availability"
    }
  ];
}

// Request message for the `UpdateAvailability` method.
message UpdateAvailabilityRequest {
  // Required. The availability to update.
  Availability availability = 1 [(google.api.field_behavior) = REQUIRED];

  // Required. The list of fields to update.
  // The only field that can be updated is `custom_status`.
  google.protobuf.FieldMask update_mask = 2
      [(google.api.field_behavior) = REQUIRED];
}

// Request message for the `MarkAsActive` method.
message MarkAsActiveRequest {
  // Required. The resource name of the availability to mark as active.
  // Format: users/{user}/availability
  //
  // `{user}` is the id for the Person in the People API or Admin SDK directory
  // API. For example, `users/123456789`.
  //
  // The user's email address or `me` can also be used as an alias to refer to
  // the caller.  For example, `users/user@example.com` or `users/me`.
  string name = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "chat.googleapis.com/Availability"
    }
  ];

  // The expiration for the ACTIVE availability state. The user will
  // be marked as Away after expiration. If no expiration is provided, the
  // ACTIVE state will expire 30 minutes from the current time.
  oneof expiration {
    // The absolute timestamp when the ACTIVE state expires.
    google.protobuf.Timestamp expire_time = 2;

    // The duration from the current time until the ACTIVE state expires.
    // Using a short TTL can effectively reset the user's state to be based
    // on activity after this brief duration.
    google.protobuf.Duration ttl = 3;
  }
}

// Request message for the `MarkAsAway` method.
message MarkAsAwayRequest {
  // Required. The resource name of the availability to mark as away.
  // Format: users/{user}/availability
  //
  // `{user}` is the id for the Person in the People API or Admin SDK directory
  // API. For example, `users/123456789`.
  //
  // The user's email address or `me` can also be used as an alias to refer to
  // the caller.  For example, `users/user@example.com` or `users/me`.
  string name = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "chat.googleapis.com/Availability"
    }
  ];
}

// Request message for the `MarkAsDoNotDisturb` method.
message MarkAsDoNotDisturbRequest {
  // Required. The resource name of the availability to mark as Do Not Disturb.
  // Format: users/{user}/availability
  //
  // `{user}` is the id for the Person in the People API or Admin SDK directory
  // API. For example, `users/123456789`.
  //
  // The user's email address or `me` can also be used as an alias to refer to
  // the caller.  For example, `users/user@example.com` or `users/me`.
  string name = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "chat.googleapis.com/Availability"
    }
  ];

  // Required. The expiration for the DND availability state. The user will be
  // marked as Away after expiration. This can be at most 1 year from the
  // current time.
  oneof expiration {
    // The absolute timestamp when the DND state expires.
    google.protobuf.Timestamp expire_time = 2;

    // The duration from the current time until the DND state expires.
    google.protobuf.Duration ttl = 3;
  }
}
