syntax = "proto3";

package wix.devcenter.apps.v1;
option java_package = "com.wixpress.devcenter.apps.v1";

import "google/protobuf/wrappers.proto";
import "google/api/annotations.proto";
import "wix/api/annotations.proto";
import "wix/api/entity.proto";
import "wix/api/callback.proto";
import "wix/api/permissions.proto";
import "wix/api/validations.proto";
import "AppInvite.proto";
import "com/wixpress/invites/api/invites.proto";
import "people.proto";
import "app-roles-management-service.proto";

/**
  This is just a PROXY service for calling the "real" services that handles the App's invitations and collaborators.
  It was created to serve the Devcenter and AppMarket employees that needs permissions to the Roles & Permissions of apps that they do NOT own nor collaborate on.
 */
service AppInvitesProxyService {
    option (.wix.api.service_maturity) = BETA;
    option (wix.api.service_entity).message = "wix.devcenter.apps.v1.AppInviteProxy"; //Dummy message
    option (.wix.api.service_exposure) = PUBLIC;

    rpc CreateAppInviteProxy (CreateAppInviteProxyRequest) returns (CreateAppInviteProxyResponse){
        option (google.api.http).post = "/v1/apps/invites";
        option (.wix.api.permission) = {
            name: "DUMMY" //No need for a permission since its just a proxy service
            type: MANUAL
        };
    }


    rpc DeleteAppInviteProxy (DeleteAppInviteProxyRequest) returns (DeleteAppInviteProxyResponse){
        option (google.api.http).delete = "/v1/apps/invites/{invite_id}";
        option (.wix.api.permission) = {
            name: "DUMMY" //No need for a permission since its just a proxy service
            type: MANUAL
        };
        option (.wix.api.crud) = {
            method: DELETE
            delete_options: {
                id_field: "invite_id"
            }
        };
        option (.wix.api.callback) = {
            event_type: DELETED
        };
    }

    rpc ResetAppInviteProxy (ResetAppInviteProxyRequest) returns (ResetAppInviteProxyResponse){
        option (google.api.http).post = "/v1/apps/invites/{invite_id}/reset";
        option (.wix.api.permission) = {
            name: "DUMMY" //No need for a permission since its just a proxy service
            type: MANUAL
        };
    };

    rpc GetAppContributorsProxy (GetAppContributorsProxyRequest) returns (GetAppContributorsProxyResponse){
        option (google.api.http).get = "/v1/apps/contributors/{app_id}";
        option (.wix.api.permission) = {
            name: "DUMMY" //No need for a permission since its just a proxy service
            type: MANUAL
        };
    }

    rpc ClearAssignedAppPoliciesProxy (ClearAssignedAppPoliciesProxyRequest) returns (ClearAssignedAppPoliciesProxyResponse) {
        option (google.api.http).delete = "/v1/apps/{app_id}/account/{account_id}/assigned-policies";
        option (.wix.api.permission) = {
            name: "DUMMY" //No need for a permission since its just a proxy service
            type: MANUAL
        };
    }
}

//Dummy message
message AppInviteProxy {
    // flynt-disable missing-extensible
    option (.wix.api.entity) = {
        fqdn: "wix.devcenter.apps.v1.app_invite_proxy"
        segment: USERS
        app_def_id: "98d127ae-4388-4027-91b7-270768b84398"
    };
    google.protobuf.StringValue id = 1 [(.wix.api.format) = GUID];
}

message CreateAppInviteProxyRequest {
    com.wixpress.authorization.invite.service.AppInvite invite = 1;
}

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

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

message GetAppContributorsProxyRequest {
    string app_id = 1 [(wix.api.format) = GUID];
    google.protobuf.StringValue locale = 2 [(wix.api.maxLength) = 10];
}

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

message CreateAppInviteProxyResponse {
    com.wixpress.invites.api.AppWebInvite invite = 1;
}

message DeleteAppInviteProxyResponse {}

message ResetAppInviteProxyResponse {
    com.wixpress.invites.api.AppWebInvite invite = 1;
}

message GetAppContributorsProxyResponse {
    repeated com.wixpress.roles.management.api.Contributor contributors = 1;
    repeated com.wixpress.roles.management.api.AppInvite invites = 2;
}

message ClearAssignedAppPoliciesProxyResponse {
    repeated string deleted_assignment_ids = 1 [(wix.api.format) = GUID];
}
