// flynt-disable missing-entity-id-field

syntax = "proto3";

import "google/protobuf/struct.proto";
import "google/protobuf/timestamp.proto";
import "google/protobuf/wrappers.proto";
import "google/api/annotations.proto";
import "wix/api/validations.proto";
import "wix/api/annotations.proto";
import "wix/api/entity.proto";
import "wix/api/permissions.proto";

package com.wix.fed.settings;

message Empty {
}

message UserPreferences {
  option (.wix.api.entity) = {
    fqdn: "wix.app_settings.v1.user_preferences",
    segment: USERS
  };
  // We are bound to camel case notation to support migration of existing endpoints
  google.protobuf.StringValue userId = 1;
  google.protobuf.StringValue nameSpace = 2;
  google.protobuf.StringValue siteId = 3;
  google.protobuf.StringValue key = 4;
  google.protobuf.Value blob = 5;
  google.protobuf.Timestamp dateCreated = 6;
  google.protobuf.Timestamp dateUpdated = 7;
  google.protobuf.Int32Value TTLInDays = 8;
}

message DeleteEntryDto {
  google.protobuf.StringValue nameSpace = 1;
  google.protobuf.StringValue siteId = 2;
  google.protobuf.StringValue key = 3;
}

message BulkSetDto {
  google.protobuf.StringValue nameSpace = 1;
  google.protobuf.StringValue siteId = 2;
  google.protobuf.Int32Value TTLInDays = 3;
  map<string, google.protobuf.Value> data = 4;
}

message GetUserPreferencesRequest {
  google.protobuf.StringValue userId = 1;
  google.protobuf.StringValue nameSpace = 2;
  google.protobuf.StringValue key = 3;
  google.protobuf.StringValue siteId = 4;
}

message GetUserPreferencesResponse {
  repeated UserPreferences userPreferences = 1;
}

message BulkGetByUserSitesRequest {
  google.protobuf.StringValue nameSpace = 1;
  google.protobuf.StringValue key = 2;
  google.protobuf.StringValue userId = 3;
  repeated google.protobuf.StringValue siteIds = 4;
}

message BulkGetByUserSitesResponse {
  repeated UserPreferences userPreferences = 1;
}

message BulkGetUserPreferencesRequest {
  repeated google.protobuf.StringValue userIds = 1;
  google.protobuf.StringValue nameSpace = 2;
  google.protobuf.StringValue key = 3;
  google.protobuf.StringValue siteId = 4;
}

message BulkGetUserPreferencesResponse {
  repeated UserPreferences userPreferences = 1;
}

message BulkSetUserPrefencesRequest {
  BulkSetDto bulkSetDto = 1;
  google.protobuf.StringValue userId = 2;
}

message BulkSetUserPrefencesResponse {
  repeated UserPreferences userPreferences = 1;
}

message DeleteUserPrefencesRequest {
  DeleteEntryDto deleteDto = 1;
  google.protobuf.StringValue userId = 2;
}

service UserPreferencesService {

  option (.wix.api.service_entity).message = "com.wix.fed.settings.UserPreferences";


  rpc Get (GetUserPreferencesRequest) returns (GetUserPreferencesResponse) {
    option (.wix.api.required) = "GetUserPreferencesRequest.userId";
    option (.wix.api.required) = "GetUserPreferencesRequest.nameSpace";
  }

  rpc BulkGetByUserSites (BulkGetByUserSitesRequest) returns (BulkGetByUserSitesResponse) {
    option (.wix.api.required) = "BulkGetByUserSitesRequest.userId";
    option (.wix.api.required) = "BulkGetByUserSitesRequest.nameSpace";
    option (.wix.api.required) = "BulkGetByUserSitesRequest.siteIds";
  }

  rpc BulkGet (BulkGetUserPreferencesRequest) returns (BulkGetUserPreferencesResponse) {
    option (.wix.api.required) = "BulkGetUserPreferencesRequest.userIds";
    option (.wix.api.required) = "BulkGetUserPreferencesRequest.nameSpace";
  }

  rpc Set (UserPreferences) returns (UserPreferences) {
    option (.wix.api.required) = "UserPreferences.userId";
    option (.wix.api.required) = "UserPreferences.nameSpace";
    option (.wix.api.required) = "UserPreferences.key";
    option (.wix.api.required) = "UserPreferences.blob";
  }

  rpc BulkSet (BulkSetUserPrefencesRequest) returns (BulkSetUserPrefencesResponse) {
    option (.wix.api.required) = "BulkSetUserPrefencesRequest.userId";
    option (.wix.api.required) = "BulkSetUserPrefencesRequest.bulkSetDto.nameSpace";
    option (.wix.api.required) = "BulkSetUserPrefencesRequest.bulkSetDto.data";
  }

  rpc Delete (DeleteUserPrefencesRequest) returns (Empty) {
    option (.wix.api.required) = "DeleteUserPrefencesRequest.userId";
    option (.wix.api.required) = "DeleteUserPrefencesRequest.deleteDto.nameSpace";
    option (.wix.api.required) = "DeleteUserPrefencesRequest.deleteDto.key";
  }
}

message AccountPreferences {
  option (.wix.api.entity) = {
    fqdn: "wix.app_settings.v1.account_preferences",
    segment: USERS
  };
  google.protobuf.StringValue account_id = 1 [(.wix.api.format)=GUID];
  google.protobuf.StringValue namespace = 2 [(.wix.api.minLength) = 1, (.wix.api.maxLength) = 256];
  google.protobuf.StringValue key = 3 [(.wix.api.minLength) = 1, (.wix.api.maxLength) = 256];
  google.protobuf.Value blob = 4;
  google.protobuf.Timestamp date_created = 5;
  google.protobuf.Timestamp date_updated = 6;
  google.protobuf.Int32Value ttl_in_days = 7;
}

message GetAccountPreferencesRequest {
  google.protobuf.StringValue account_id = 1 [(.wix.api.format)=GUID];
  google.protobuf.StringValue namespace = 2 [(.wix.api.minLength) = 1, (.wix.api.maxLength) = 256];
  google.protobuf.StringValue key = 3 [(.wix.api.minLength) = 1, (.wix.api.maxLength) = 256];
}

message DeleteAccountPreferencesRequest {
  google.protobuf.StringValue account_id = 1 [(.wix.api.format)=GUID];
  google.protobuf.StringValue namespace = 2 [(.wix.api.minLength) = 1, (.wix.api.maxLength) = 256];
  google.protobuf.StringValue key = 3 [(.wix.api.minLength) = 1, (.wix.api.maxLength) = 256];
}

message GetAccountPreferencesResponse {
  repeated AccountPreferences account_preferences = 1;
}

service AccountPreferencesService {
  option (.wix.api.service_entity).message = "com.wix.fed.settings.AccountPreferences";

  rpc GetAccountPreferences (GetAccountPreferencesRequest) returns (GetAccountPreferencesResponse) {
    option (.wix.api.required) = "GetAccountPreferencesRequest.account_id";
    option (.wix.api.required) = "GetAccountPreferencesRequest.namespace";
    option (.wix.api.permission).name = "ACCOUNT_PREFERENCES.READ";
  }

  rpc SetAccountPreferences (AccountPreferences) returns (AccountPreferences) {
    option (.wix.api.required) = "AccountPreferences.account_id";
    option (.wix.api.required) = "AccountPreferences.namespace";
    option (.wix.api.required) = "AccountPreferences.key";
    option (.wix.api.required) = "AccountPreferences.blob";
    option (.wix.api.permission).name = "ACCOUNT_PREFERENCES.MANAGE";
  }

  rpc DeleteAccountPreferences (DeleteAccountPreferencesRequest) returns (Empty) {
    option (.wix.api.required) = "DeleteAccountPreferencesRequest.account_id";
    option (.wix.api.required) = "DeleteAccountPreferencesRequest.namespace";
    option (.wix.api.required) = "DeleteAccountPreferencesRequest.key";
    option (.wix.api.permission).name = "ACCOUNT_PREFERENCES.MANAGE";
  }
}
