/*
 * Copyright (C) 2025 The Android Open Source Project
 *
 * 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.
 */

edition = "2023";

package cuttlefish.config;

enum GpuMode {
  GPU_MODE_UNKNOWN = 0;
  GPU_MODE_AUTO = 1;
  GPU_MODE_CUSTOM = 2;
  GPU_MODE_DRM_VIRGL = 3;
  GPU_MODE_GFXSTREAM = 4;
  GPU_MODE_GFXSTREAM_GUEST_ANGLE = 5;
  GPU_MODE_GFXSTREAM_GUEST_ANGLE_HOST_LAVAPIPE = 6;
  GPU_MODE_GFXSTREAM_GUEST_ANGLE_HOST_SWIFTSHADER = 7;
  GPU_MODE_GUEST_SWIFTSHADER = 8;
  GPU_MODE_NONE = 9;
}

message Graphics {
  // Whether the guest supports the Gfxstream graphics driver.
  bool gfxstream_supported = 1;

  // Whether the guest supports the Gfxstream GL program binary link status
  // feature.
  bool gfxstream_gl_program_binary_link_status_supported = 2;

  // Whether the guest UI can use the BGRA pixel format for its framebuffers.
  bool bgra_framebuffers_supported = 3;

  // If true, the system will prefer using the drm_virgl display mode when
  // available.
  bool prefer_drm_virgl_when_supported = 4;

  // The list of gpu modes supported by the guest in order of preference.
  repeated GpuMode gpu_mode_candidates = 5;

  // Whether the guest has a separate apex for the Gfxstream Vulkan driver.
  bool vulkan_gfxstream_apex_supported = 6;

  // Whether the guest has a separate apex for the Lavapipe Vulkan driver.
  bool vulkan_lavapipe_apex_supported = 7;

  // Whether the guest has a separate apex for the Swiftshader Vulkan driver.
  bool vulkan_swiftshader_apex_supported = 8;
}

message Audio {
  enum ChannelLayout {
    option features.enum_type = CLOSED;

    UNKNOWN = 0;
    // Single channel
    MONO = 1;
    // Channel order: FL, FR
    STEREO = 2;
    // Channel order: FL, FR, FC, LFE, SL, SR
    SURROUND51 = 3;
  }

  enum SampleRate {
    option features.enum_type = CLOSED;
    RATE_UNKNOWN = 0;
    RATE_32000 = 1;
    RATE_44100 = 2;
    RATE_48000 = 3;
    RATE_64000 = 4;
  }

  message AudioMixer {
    ChannelLayout channel_layout = 1;
    SampleRate sample_rate = 2;
  }

  message PCMDevice {

    message Controls {
      message Volume {
        uint32 min = 1;
        uint32 max = 2;
        uint32 step = 3;
      }
      bool mute_control_enabled = 1;
      Volume volume_control = 2;
    }

    message Stream {
      uint32 id = 1;
      ChannelLayout channel_layout = 2;
      Controls controls = 3;
    }
    repeated Stream capture_streams = 1;
    repeated Stream playback_streams = 2;
    AudioMixer mixer = 3;
  }

  repeated PCMDevice pcm_devices = 1;
}

message Input {
  // Indicates whether the guest has native support for a mouse.
  bool mouse_supported = 1;

  // Indicates whether the guest has native support for a gamepad or controller.
  bool gamepad_supported = 2;

  // An optional path to a custom keyboard configuration file.
  // The path is relative to the host artifacts directory.
  string custom_keyboard_config = 3;

  // An optional path to a custom DOM key mapping file for keyboard translation.
  // The path is relative to the host artifacts directory.
  string domkey_mapping_config = 4;
}

message Network {
  // If set, forces the use of mac80211_hwsim for Wi-Fi simulation.
  bool enforce_mac80211_hwsim = 1;
}

message Storage {
  // The size in megabytes for a blank userdata.img if one is not provided.
  int32 blank_data_image_mb = 1;
}

message Virtualization {
  // Whether the guest supports vhost-user-vsock for virtualized socket
  // communication.
  bool vhost_user_vsock = 1;

  // An optional path to a Titan C (ti50) security chip emulator binary.
  string ti50_emulator_path = 2;
}

// Specifies the type of the emulated device
enum DeviceType {
  Unknown = 0;
  Phone = 1;
  Wear = 2;
  Auto = 3;
  Foldable = 4;
  Tv = 5;
  Minidroid = 6;
  Go = 7;
  Desktop = 8;
}

// The presence of this field in the proto indicates the lights HAL is enabled.
message Lights {}

// GuestConfigFile represents the configuration for a Cuttlefish guest device,
// typically parsed from a cuttlefish-guest-config.txtpb file. It defines the
// device's hardware capabilities, software features, and virtualization
// settings.
message GuestConfigFile {
  DeviceType device_type = 1;

  Graphics graphics = 2;

  Input input = 3;

  Audio audio = 4;

  Network network = 5;

  Storage storage = 6;

  Virtualization virtualization = 7;

  Lights lights = 8;
}
