/*
 * SPDX-FileCopyrightText: 2025 microG project team
 * SPDX-License-Identifier: Apache-2.0
 */

syntax = "proto3";

option java_package = "org.microg.vending.billing.proto";
option java_multiple_files = true;

import "Timestamp.proto";


message SkuDetailsRequest {
  int32 apiVersion = 1;
  string package = 2;
  string type = 3;
  repeated string skuId = 4;
  repeated DynamicSku dynamicSku = 5;
  bool isWifi = 6;
  SkuDetailsExtra skuDetailsExtra = 7;
  string skuPackage = 8;
  repeated OfferSku offerSkus = 9;
  repeated MultiOfferSkuDetail multiOfferSkuDetail = 10;
}

message AcquireRequest {
  DocumentInfo documentInfo = 1;
  ClientInfo clientInfo = 2;
  bytes serverContextToken = 3;
  repeated bytes actionContext = 4;
  string clientTokenB64 = 5;
  DeviceAuthInfo deviceAuthInfo = 8;
  map<string, string> authTokens = 9;
  UnkMessage5 unknown12 = 12;
  string deviceIDBase64 = 19;
  string newAcquireCacheKey = 20;
  string nonce = 22;
  int32 theme = 25;
  Timestamp ts = 31;
}

message CKDocument {
  DocId docId = 1;
  oneof SkuOfferIdToken {
    string token3 = 2;
    string token14 = 4;
  }
  int32 unknown3 = 3;
}

message DeviceAuthInfo {
  bool canAuthenticate = 1; 
  bool isBiometricStrong = 2;
  bool fingerprintValid = 3;
  int32 desiredAuthMethod = 4;
  int32 unknown5 = 5;
  int32 authFrequency = 6;
  bool unknown9 = 9;
  bool userHasFop = 16;
  map<string, string> authParams = 18;
  bool unknown20 = 20;
  ItemColor itemColor = 26;
  string droidGuardPayload = 30;
}

message UnkMessage5 {
  int32 unknown1 = 1;
}

message ItemColor {
  int32 androidAppsColor = 1;
  int32 booksColor = 2;
  int32 musicColor = 3;
  int32 moviesColor = 4;
  int32 newsStandColor = 5;
}

message ClientInfo {
  int32 apiVersion = 1;
  string package = 2;
  int32 versionCode = 3;
  string signatureMD5 = 4;
  repeated SkuParam skuParamList = 7;
  int32 unknown8 = 8;
  string installerPackage = 9;
  bool unknown10 = 10;
  bool unknown11 = 11;
  UnkMessage1 unknown15 = 15;
  oneof OldSkuPurchase {
    string oldSkuPurchaseToken = 16;
    string oldSkuPurchaseId = 17;
  }
  int32 versionCode1 = 18;
}

message ClientToken {
  Info1 info1 = 1;
  Info2 info2 = 2;
  message Info1 {
    bytes unknown2 = 2;
    string locale = 7;
    int32 unknown8 = 8;
    int64 gpVersionCode = 9;
    DeviceInfo deviceInfo = 10;
    string unknown11 = 11;
    repeated string googleAccounts = 19;
  }
  message Info2 {
    string unknown1 = 1;
    int32 unknown3 = 3;
    repeated int32 unknown4 = 4;
    int32 unknown5 = 5;
  }
  message DeviceInfo {
    string unknown3 = 3;
    string device = 4;
    int32 widthPixels = 5;
    int32 heightPixels = 6;
    float xdpi = 7;
    float ydpi = 8;
    string gpPackage = 9;
    string gpVersionCode = 10;
    string gpVersionName = 11;
    EnvInfo envInfo = 12;
    string callingPackage = 13;
    string marketClientId = 14;
    int32 unknown15 = 15;
    int32 unknown16 = 16;
    string simOperatorName = 17;
    string groupIdLevel1 = 18;
    int64 subscriberId = 19;
    int32 unknown22 = 22;
    int64 linkDownstreamBandwidth = 23;
    int64 linkUpstreamBandwidth = 24;
    bool  isActiveNetworkMetered = 25;
    int32 densityDpi = 28;
    int32 unknown34 = 34;
    int64 uptimeMillis = 35;
    string timeZoneDisplayName = 36;
    int32 unknown40 = 40;
  }

  message EnvInfo {
    DeviceData deviceData = 1;
    OtherInfo otherInfo = 2;
  }

  message DeviceData {
    int32 unknown1 = 1;
    string simOperatorName = 2;
    string phoneDeviceId = 3;
    string phoneDeviceId1 = 5;
    string line1Number = 6;
    int64 gsfId = 7;
    string device = 9;
    string product = 10;
    string model = 11;
    string manufacturer = 12;
    string fingerprint = 13;
    string release = 15;
    string brand = 21;
    string serial = 22;
    bool isEmulator = 24;
  }

  message OtherInfo {
    repeated GPInfo gpInfo = 1;
    int32 batteryLevel = 3;
    int64 timeZoneOffset = 4;
    Location location = 6;
    bool isAdbEnabled = 7;
    bool installNonMarketApps = 8;
    string iso3Language = 9;
    repeated string netAddress = 10;
    string locale = 11;
    string networkOperator = 14;
    string simOperator = 15;
    string language = 18;
    string country = 19;
    int32 phoneType = 20;
    int64 uptimeMillis = 21;
    string timeZoneDisplayName = 22;
    int32 googleAccountCount = 23;
    bool isUserAMonkey = 24;
    bool isAudioWork = 25;
    bool hasUsbFeature = 26;
    bool isChanging = 27;
    int32 brightness = 28;
  }
  message GPInfo {
    string package = 1;
    string versionCode = 2;
    int64 lastUpdateTime = 3;
    int64 firstInstallTime = 4;
    string sourceDir = 5;
  }
  message Location {
    double altitude = 1;
    double latitude = 2;
    double longitude = 3;
    float accuracy = 4;
    double time = 5;
    bool isMock = 6;
  }
}

message UnkMessage1 {
  oneof Type {
    UnkMessage2 unknown1 = 1;
    UnkMessage3 unknown2 = 2;
    UnkMessage4 unknown3 = 3;
  }
}

message UnkMessage2 {
  int32 unknown1 = 1;
}

message UnkMessage3 {
  int32 unknown1 = 1;
}

message UnkMessage4 {
  int32 unknown1 = 1;
}

message SkuParam {
  string name = 1;
  string sv = 2;
  bool bv = 3;
  int64 i64v = 4;
  repeated string svList = 5;
}

message DocumentInfo {
  DocId docId = 1;
  int32 unknown2 = 2;
  oneof SkuOfferIdToken {
    string token3 = 3;
    string token14 = 14;
  }
}

message AcknowledgePurchaseRequest {
  string purchaseToken = 1;
  string developerPayload = 2;
}

message MultiOfferSkuDetail {
  string key = 1;
  oneof value {
    string sv = 2;
    bool  bv = 3;
    int64 iv = 4;
    SkuSerializedDocIds skuSerializedDocIds = 5;
  }
}

message SkuSerializedDocIds {
  repeated string docIds = 1;
}

message OfferSku {
  string unknown1 = 1;
  string unknown2 = 2;
}

message SkuDetailsExtra {
  string version = 1;
}

message DynamicSku {
  string unknown1 = 1;
  string unknown2 = 2;
  string unknown3 = 3;
}

message DetailsResponse {
  Item item = 4;
}

message BuyResponse {
  string deliveryToken = 55;
}

message Item {
  Offer offer = 8;
  repeated Item subItem = 11;
  DocumentDetails details = 13;
}

message DocumentDetails {
  AppDetails appDetails = 1;
}

message AppDetails {
  int32 versionCode = 3;
  string packageName = 14;
}

message Offer {
  int64 micros = 1;
  int32 offerType = 8;
  string offerId = 19;
}

message AcquireResponse {
  map<string, Screen> screen = 1;
  AcquireResult acquireResult = 3;
  bytes serverContextToken = 4;
  Action action = 8;
  bool needClear = 11;
}

message AcquireResult {
  repeated PurchaseItem purchaseItem = 3;
  OwnedPurchase ownedPurchase = 8;
  string signature = 9;
  PurchaseResponse purchaseResponse = 10;
}

message OwnedPurchase {
  repeated PurchaseItem purchaseItem = 1;
}

message PurchaseResponse {
  bool isSuccessful = 1;
  ResponseBundle responseBundle = 2;
}

message ResponseBundle {
  repeated BundleItem bundleItem = 1;
}

message BundleItem {
  string key = 1;
  oneof value {
    string sv = 2;
    bool bv = 3;
    int64 i64v = 4;
    int32 i32v = 5;
    BundleStringList sList = 6;
  }
}

message BundleStringList {
  repeated string value = 1;
}

message Screen {
  UIInfo uiInfo = 1;
  Action action = 5;
  UiComponents uiComponents = 175996169;
}

message UiComponents {
  repeated ContentComponent contentComponent1 = 1;
  repeated ContentComponent contentComponent2 = 2;
  repeated FooterComponent footerComponent = 3;
}

message ContentComponent {
  UIInfo uiInfo = 1;
  ViewInfo viewInfo = 2;
  string tag = 4;
  oneof UiComponent {
    ClickableTextView clickableTextView = 20;
    ViewGroup viewGroup = 21;
    DividerView dividerView = 23;
    InstrumentItemView instrumentItemView = 26;
    ModuloImageView moduloImageView = 27;
    IconTextCombinationView iconTextCombinationView = 37;
    ButtonGroupView buttonGroupView = 57;
  }
}

message InstrumentItemView {
  ImageView icon = 1;
  PlayTextView text = 2;
  PlayTextView tips = 3;
  ImageView state = 5;
  Action action = 6;
  PlayTextView extraInfo = 7;
}

message ModuloImageView {
  ImageView imageView = 1;
  Action action = 2;
}

message DividerView {
}

message ClickableTextView {
  PlayTextView playTextView = 1;
  Action action = 2;
}

message IconView {
  int32 type = 1;
  string text = 2;
}

message ImageInfo {
  oneof ColorFilter{
    int32 value = 1;
    int32 valueType = 3;
  }
  int32 modeType = 2;
  int32 scaleType = 5;
}

message ImageView {
  ThumbnailImageView thumbnailImageView = 1;
  ViewInfo viewInfo = 2;
  ImageInfo imageInfo = 4;
  IconView iconView = 5;
  oneof AnimationType{
    Animation animation = 6;
  }
}

message Animation {
  int32 type = 1;
  int32 repeatCount = 2;
}

message ViewGroup {
  ImageView imageView1 = 1;
  ImageView imageView2 = 2;
  ImageView imageView3 = 3;
  ImageView imageView4 = 4;
  PlayTextView playTextView = 5;
}

message ViewInfo {
  string tag = 1;
  float widthValue = 2;
  float heightValue = 3;
  float startMargin = 4;
  float topMargin = 5;
  float endMargin = 6;
  float bottomMargin = 7;
  float startPadding = 8;
  float topPadding = 9;
  float endPadding = 10;
  float bottomPadding = 11;
  int32 backgroundColor = 12;
  int32 backgroundColorType = 37;
  string contentDescription = 14;
  Action action = 20;
  repeated int32 gravity = 22;
  int32 widthTypedValue = 23;
  int32 heightTypedValue = 24;
  int32 visibilityType = 29;
  int32 borderColorType = 30;
  int32 startMarginType = 41;
  int32 topMarginType = 42;
  int32 endMarginType = 43;
  int32 bottomMarginType = 44;
  int32 startPaddingType = 45;
  int32 topPaddingType = 46;
  int32 endPaddingType = 47;
  int32 bottomPaddingType = 48;
}

message ThumbnailImageView {
  string lightUrl = 5;
  string darkUrl = 28;
}

message ImageGroup {
  repeated ImageView imageView = 1;
  ViewInfo viewInfo = 2;
}

message IconTextCombinationView {
  ImageView headerImageView = 1;
  PlayTextView playTextView = 2;
  repeated SingleLineTextView singleLineTextView = 5;
  ViewInfo viewInfo = 6;
  PlayTextView badgeTextView = 9;
  ImageGroup footerImageGroup = 12;
}

message SingleLineTextView {
  PlayTextView playTextView1 = 1;
  PlayTextView playTextView2 = 2;
}

message Dimension {
  int32 unitType = 1;
  float unitValue = 2;
}

message BulletSpan {
  Dimension gapWidth = 1;
}

message TextSpan {
  oneof Span {
    BulletSpan bulletSpan = 4;
  }
}

message PlayTextView {
  oneof TextData {
    string text = 1;
    int32 textType = 10;
  }
  bool isHtml = 2;
  ViewInfo viewInfo = 3;
  TextInfo textInfo = 4;
  repeated TextSpan textSpan = 7;
}

message TextInfo {
  oneof TextColor {
    int32 textColorValue = 2;
    int32 textColorType = 39;
  }
  int32 maxLines = 6;
  repeated int32 gravity = 17;
  int32 textAlignmentType = 36;
  int32 styleType = 41;
}

message FooterComponent {
  UIInfo uiInfo = 1;
  ViewInfo viewInfo = 2;
  string tag = 5;
  oneof UiComponent {
    ButtonGroupView buttonGroupView = 22;
    DividerView dividerView = 24;
    IconTextCombinationView iconTextCombinationView = 25;
  }
}

message ButtonGroupView {
  NewButtonView newButtonView = 6;
}

message NewButtonView {
  ButtonView buttonView = 1;
  ButtonView buttonView2 = 2;
}

message ButtonView {
  oneof TextData {
    string text = 1;
    int32 fixedTextType = 9;
  }
  Action action = 2;
  ViewInfo viewInfo = 4;
}

message UIInfo {
  int32 uiType = 1;
  bytes context = 2;
  int32 classType = 5;
}

message NavigateToPage {
  string id = 1;
  string from = 2;
  Action action = 3;
}

message Action {
  TimerAction timerAction = 3;
  ShowAction showAction = 4;
  bytes actionContext = 7;
  NavigateToPage navigateToPage = 8;
  ViewClickAction viewClickAction = 10;
  OptionalAction optionalAction = 19;
  ActionExt actionExt = 148814548;
}

message OptionalAction {
  repeated int32 unknown1 = 1;
  Action action1 = 2;
  Action action2 = 3;
}

message ViewClickAction {
  UIInfo uiInfo = 2;
  Action action = 3;
}

message TimerAction {
  ResponseBundle responseBundle = 1;
  bool isSuccessful = 2;
  int32 delay = 3;
  string url = 4;
}

message ShowAction {
  string screenId = 1;
  Action action = 7;
  Action action1 = 8;
}

message ExtAction {
  Action action = 1;
  DroidGuardMap droidGuardMap = 20;
}

message IABX {
  repeated SkuParam skuParam = 1;
}

message DroidGuardMap {
  map<string, string> map = 1;
  int32 type = 2;
}

message ActionExt {
  ExtAction extAction = 1;
}

message AcknowledgePurchaseResponse {
  PurchaseItem purchaseItem = 1;
  FailedResponse failedResponse = 2;
}

message SkuDetailsResponse {
  repeated SkuDetails details = 1;
  bool unknown2 = 2;
  FailedResponse failedResponse = 4;
  repeated SkuInfo skuInfo = 6;
}

message SkuInfo {
  repeated SkuItem skuItem = 1;
}

message SkuItem {
  DocId docId = 1;
  string unknown2 = 2;
  string token = 3;
}

message DocId {
  string backendDocId = 1;
  int32 type = 2;
  int32 backend = 3;
}

message SkuDetails {
  string skuDetails = 1;
  SkuInfo skuInfo = 4;
}

message ConsumePurchaseResponse {
  PurchaseItem purchaseItem = 1;
  FailedResponse failedResponse = 3;
}

message PurchaseItem {
  repeated PurchaseItemData purchaseItemData = 4;
}

message PurchaseItemData {
  DocId docId = 1;
  SubsPurchase subsPurchase = 6;
  InAppPurchase inAppPurchase = 7;
}

message InAppPurchase {
  string jsonData = 1;
  string signature = 2;
}

message SubsPurchase {
  int64 startAt = 1;
  int64 expireAt = 2;
  string jsonData = 5;
  string signature = 6;
}

message FailedResponse {
  int32 statusCode = 1;
  string msg = 2;
}

message PurchaseHistoryResponse {
  repeated string productId = 1;
  repeated string purchaseJson = 2;
  repeated string signature = 3;
  string continuationToken = 4;
  FailedResponse failedResponse = 5;
}