syntax = "proto3";

package com.wixpress.appservice.api;

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

option java_package = "com.wixpress.appservice.api";

message DeletePermissionRequest {
    string app_id = 1 [(wix.api.format) = GUID];
    string permission_id = 2 [(wix.api.minLength) = 1]; // permission id from permission-catalog-api
}

message DeletePermissionsResponse {}

message AddOrUpdateAppUriRequest {
    string app_id = 1 [(wix.api.format) = GUID];
    google.protobuf.StringValue app_uri = 2 [(wix.api.format) = URI];
    OpenConsentIn open_consent_in = 3;
    google.protobuf.BoolValue silent_consent = 4;
}

message UpdateRedirectUrisRequest {
    string app_id = 1 [(wix.api.format) = GUID];
    repeated string redirect_uris = 2 [(wix.api.format) = URI];
}

message AddOrUpdateAppUriResponse {

}

message UpdateRedirectUrisResponse {
}

// Sign up for a specific permission
message RegisterForPermissionRequest {
    string app_id = 1 [(wix.api.format) = GUID];
    string permission_id = 2 [(wix.api.minLength) = 1]; // permission id from permission-catalog-api
}

message RegisterForPermissionResponse {
}

message Permission {
    option (.wix.api.entity) = {
        fqdn: "wix.devcenter.permissions.v1.permission"
        segment: USERS
    };
    string permission_id = 2;
}

message PermissionWithStatus {
    string permission_id = 2;
    google.protobuf.StringValue status = 3;
}

message AppPermissionMessageValue {
    repeated Permission permission = 1;
}

message AppPermissionMessage {
    string key = 1; // key = "${appId}:${version}"
    AppPermissionMessageValue value = 2;
}

enum OpenConsentIn {
    NONE_VALUE = 0;
    NEW_WINDOW = 1;
    NEW_TAB = 2;
}

message AppAuthData {
    repeated string redirect_uris = 1; //list of redirect urls of OAuth
    google.protobuf.StringValue app_uri = 2;// the app url of OAuth
    OpenConsentIn open_consent_in = 3; // How the consent (installation flow) should be opened
    bool silent_consent = 4; // Whether this app should skip consent
    UninstallActions uninstall_action = 5; // Whether uninstalling should be blocked until further actions are taken
}

message AppRedirectUrisMessage {
    string key = 1; // key = appId
    AppRedirectUrisMessageValue value = 2;
}

message AppRedirectUrisMessageValue {
    repeated string redirect_uri = 1;
}

message PermissionsAndAuthData {
    string secret = 1; // app secret, used to authenticate with oauth provider
    repeated string redirect_uris = 2;
    repeated Permission permissions = 3;
}

message UpdateAuthRequest {
    string app_id = 1 [(wix.api.format) = GUID];
    google.protobuf.StringValue app_uri = 2 [(wix.api.format) = URI];
    OpenConsentIn open_consent_in = 3;
    google.protobuf.BoolValue silent_consent = 4;
    UninstallActions uninstall_action = 5;
}

message UpdateAuthResponse {
    AppAuthData appAuthData = 1;
}

message DeleteAppUriRequest {
    string app_id = 1 [(wix.api.format) = GUID];
}

message DeleteAppUriResponse {
}

message GetPermissionsRequest {
    string app_id = 1 [(wix.api.format) = GUID];
}

message GetPermissionsResponse {
    repeated Permission permissions = 1;
}

message GetAuthDataBulkRequest {
    repeated string app_ids = 1;
}

message GetAuthDataBulkResponse {
    map<string, AppAuthData> app_id_to_auth_data = 1;
}

enum UninstallActions {
    NONE_ACTION = 0;
    NO_ACTION = 1;
    REMOVE_ALL_PRODUCT = 2;
    SHIPPING_RATES_REGION = 3;
}

message UpsertToAppPermissionsStoreRequest {
    string app_id = 1 [(wix.api.format) = GUID];
    string version = 2; // version to upsert to the app permissions store
}

message UpsertToAppPermissionsStoreResponse {
}

message OldPermissionChangedEvent {
    enum Action {
        CREATED = 0;
        UPDATED = 1;
        DELETED = 2;
    }
    string app_id = 1 [(.wix.api.format) = GUID];
    Permission permission = 2;
    Action action = 3;
}
