syntax = "proto3";

package com.wixpress.invites.api;

import "wix/api/annotations.proto";
import "wix/api/validations.proto";
import "wix/api/permissions.proto";
import "google/api/annotations.proto";
import "wix/api/entity.proto";
import "com/wixpress/invites/api/invites.proto";
import "AppInvite.proto";

service AppInvitesApi {
    option (.wix.api.service_exposure) = PRIVATE;
    option (wix.api.service_entity).message = "com.wixpress.invites.api.AppWebInvite";

    rpc CreateAppInvite (CreateAppInviteRequest) returns (CreateAppInviteResponse){
        option (google.api.http).post = "/v1/invites/app";
        option (.wix.api.required) = "CreateAppInviteRequest.invite.app_id";
        option (.wix.api.required) = "CreateAppInviteRequest.invite.policy_ids";
        option (.wix.api.required) = "CreateAppInviteRequest.invite.dest_email";
        option (.wix.api.permission) = {
            name: "DEV_CENTER.CREATE_APP_INVITE"
            type: MANUAL
        };
    }

    rpc GetAppInvite (GetAppInviteRequest) returns (GetAppInviteResponse){
        option (google.api.http).get = "/v1/invites/app/{invite_id}";
        option (.wix.api.required) = "GetAppInviteRequest.invite_id";
        option (.wix.api.permission) = {
            name: "DEV_CENTER.GET_APP_INVITE"
            type: MANUAL
        };
    }

    rpc GetAppInvites (GetAppInvitesRequest) returns (GetAppInvitesResponse){
        option (.wix.api.required) = "GetAppInvitesRequest.app_id";
        option (.wix.api.permission) = {
            name: "DEV_CENTER.GET_APP_INVITE"
            type: MANUAL
        };
    }

    rpc DeleteAppInvite (DeleteAppInviteRequest) returns (DeleteAppInviteResponse){
        option (google.api.http).delete = "/v1/invites/app/{invite_id}";
        option (.wix.api.required) = "DeleteAppInviteRequest.invite_id";
        option (.wix.api.permission) = {
            name: "DEV_CENTER.DELETE_APP_INVITE"
            type: MANUAL
        };
    }

    rpc ParseAppInviteToken (ParseAppInviteTokenRequest) returns (ParseAppInviteTokenResponse) {
        option (.wix.api.required) = "ParseAppInviteTokenRequest.invite_token";
        option (.wix.api.permission) = {
            name: "DEV_CENTER.GET_APP_INVITE"
            type: MANUAL
        };
    }

    rpc AcceptAppInvite (AcceptAppInviteRequest) returns (AcceptAppInviteResponse){
        option (.wix.api.required) = "AcceptAppInviteRequest.invite_token";
        option (.wix.api.permission) = {
            name: "DEV_CENTER.ACCEPT_APP_INVITE"
            type: MANUAL
        };
    }

    //Reset an Active (Pending/Declined/Expired) invitation by setting the invitation as "Pending" and reset its expiration date.
    rpc ResetAppInvite (ResetAppInviteRequest) returns (ResetAppInviteResponse){
        option (google.api.http).post = "/invites/app/{invite_id}/reset";
        option (.wix.api.required) = "ResetAppInviteRequest.invite_id";
        option (.wix.api.permission) = {
            name: "DEV_CENTER.RESEND_APP_INVITE"
            type: MANUAL
        };
    };
}

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

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

message GetAppInvitesRequest {
    string app_id = 1 [(wix.api.format) = GUID];
    repeated string accepted_by_account_ids = 2 [(wix.api.format) = GUID, (.wix.api.maxSize) = 100];
    repeated string statuses = 3 [(.wix.api.maxLength) = 20, (.wix.api.maxSize) = 10];
}

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

message ParseAppInviteTokenRequest {
    string invite_token = 1 [(.wix.api.maxLength) = 1000];
}

message AcceptAppInviteRequest {
    string invite_token = 1 [(.wix.api.maxLength) = 1000];
}

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

message CreateAppInviteResponse {
    AppWebInvite invite = 1;
}

message GetAppInviteResponse {
    AppWebInvite invite = 1;
}

message GetAppInvitesResponse {
    repeated AppWebInvite invites = 1;
}

message DeleteAppInviteResponse {}

message ParseAppInviteTokenResponse {
    string invite_id = 1 [(wix.api.format) = GUID];
    string app_id = 2 [(wix.api.format) = GUID];
    InviteStatus status = 3;
}

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

message ResetAppInviteResponse {
    AppWebInvite invite = 1;
}