//flynt-disable renamed-field-breaking-change, field-type-breaking-change
syntax = "proto3";

package com.wixpress.invites.api;

import "com/wixpress/invites/api/invites.proto";
import "google/api/annotations.proto";
import "google/protobuf/struct.proto";
import "wix/api/callback.proto";
import "wix/api/validations.proto";
import "wix/api/annotations.proto";
import "wix/api/permissions.proto";
import "google/protobuf/wrappers.proto";
import "wix/api/entity.proto";
import "wix/common/query.proto";

service SiteInvitesApi {
    option (wix.api.service_entity).message = "com.wixpress.invites.api.SiteInvite";

    rpc GetInvites (GetSiteInvitesRequest) returns (GetSiteInvitesResponse) {
        option (wix.api.permission).name = "site-users.view-invitations";
        option (google.api.http).get = "/invites/site";
        option (wix.api.exposure) = INTERNAL;
    };

    rpc QueryInvites (QuerySiteInvitesRequest) returns (QuerySiteInvitesResponse) {
        option (wix.api.permission).name = "site-users.view-invitations";
        option (google.api.http).post = "/invites/site/query";
        option (wix.api.exposure) = INTERNAL;
    };

    rpc GetInvite (GetSiteInviteRequest) returns (GetSiteInviteResponse) {
        option (wix.api.permission).name = "site-users.view-invitations";
        option (google.api.http).get = "/invites/site/{id}";
        option (wix.api.exposure) = INTERNAL;
        option (.wix.api.crud) = {
            method: GET_ITEM
            get_options: {
                id_field: "id"
                item_field: "invite"
            }
        };
    };

    rpc Invite (SiteInviteRequest) returns (SiteInviteResponse) {
        option (wix.api.permission).name = "site-users.send-invite";
        option (google.api.http).post = "/invites/site";
        option (wix.api.exposure) = INTERNAL;
    };

    // Creates and sends emails inviting potential site contributors to become contributors in the requesting site.
    // > **Important**: This call requires an account level API key and cannot be authenticated with the standard authorization header. API keys are currently available to selected beta users only.
    //flynt-disable http-mapping-breaking-change
    rpc BulkInvite (BulkSiteInviteRequest) returns (BulkSiteInviteResponse) {
        option (wix.api.maturity) = GA;
        option (wix.api.exposure) = PUBLIC;
        option (google.api.http) = {
            post: "/site-invite/bulk";
            additional_bindings: {
                post: "/invites/site/bulk",
            }
        };
        option (wix.api.permission).name = "site-users.send-invite";
        option (wix.api.required) = "BulkSiteInviteRequest.policy_ids";
        option (wix.api.required) = "BulkSiteInviteRequest.emails";
    };

    // Resends the email invitation to a potential site contributor.
    // > **Important**: This call requires an account level API key and cannot be authenticated with the standard authorization header. API keys are currently available to selected beta users only.
    //flynt-disable http-mapping-breaking-change
    rpc ResendInvite (ResendSiteInviteRequest) returns (SiteInviteResponse) {
        option (wix.api.maturity) = GA;
        option (wix.api.exposure) = PUBLIC;
        option (google.api.http) = {
            post: "/site-invite/{invite_id}/resend";
            additional_bindings: {
                post: "/invites/site/{invite_id}/resend",
            }
        };
        option (wix.api.permission).name = "site-users.send-invite";
        option (wix.api.required) = "ResendSiteInviteRequest.invite_id";
    };

    rpc AcceptInvite(AcceptSiteInviteRequest) returns (AcceptSiteInviteResponse) {
        option (google.api.http).post = "/invites/site/accept";
        option (wix.api.exposure) = INTERNAL;
    }

    // Revokes a pending site contributor invite.
    // > **Important**: This call requires an account level API key and cannot be authenticated with the standard authorization header. API keys are currently available to selected beta users only.
    //flynt-disable http-mapping-breaking-change
    rpc RevokeInvite (RevokeSiteInviteRequest) returns (RevokeSiteInviteResponse) {
        option (wix.api.maturity) = GA;
        option (wix.api.exposure) = PUBLIC;
        option (google.api.http) = {
            post: "/site-invite/{invite_id}/revoke";
            additional_bindings: {
                post: "/invites/site/{invite_id}/revoke",
            }
        };
        option (wix.api.permission).name = "site-users.delete-invite";
        option (wix.api.required) = "RevokeSiteInviteRequest.invite_id";
    };

    rpc UpdateInvite (UpdateSiteInviteRequest) returns (UpdateSiteInviteResponse) {
        option (google.api.http).patch = "/invites/site/{invite_id}";
        option (wix.api.permission).name = "site-users.remove-user";
        option (wix.api.exposure) = INTERNAL;
    };

    rpc GetContributorLimit(GetContributorLimitRequest) returns (GetContributorLimitResponse) {
        option (google.api.http).get = "/invites/limit/site";
        option (wix.api.exposure) = INTERNAL;
    }

    rpc ParseInviteToken (ParseSiteInviteTokenRequest) returns (ParseSiteInviteTokenResponse) {
        option (wix.api.exposure) = INTERNAL;
    }
}

message GetSiteInvitesRequest {}

message GetSiteInvitesResponse {
    repeated SiteInvite invites = 1;
}

message GetSiteInviteRequest {
    string id = 1;
}

message GetSiteInviteResponse {
    SiteInvite invite = 1;
}

message SiteInviteRequest {
    // The role ids to be assigned
    repeated string policy_ids = 1;
    // Invitee email
    string email = 2 [(wix.api.format) = EMAIL, (.wix.api.pii) = true];
    // Booking staff id
    google.protobuf.StringValue staff_id = 3 [(wix.api.format) = GUID, (wix.api.field_exposure) = INTERNAL];
    // Invite purpose
    google.protobuf.StringValue invite_purpose = 4 [(wix.api.field_exposure) = INTERNAL];
    // The language of emails that will be used only for recipients that don't have a user, in case this parameter is unspecified, the sender's language will be used instead
    google.protobuf.StringValue default_email_language = 5 [(.wix.api.pii) = false];
    // An indicator for suppressing (not sending) emails to the assignees.
    bool suppress_email = 6 [(wix.api.field_exposure) = PRIVATE];
    // Location restriction for the invite.
    LocationRestriction location_restriction = 7;

}

message SiteInviteResponse {
    //  Invites that were sent.
    SiteInvite invite = 1;
}

message QuerySiteInvitesRequest {
    // Supports only `filter` field with
    //`"filter" : {
    //    "acceptedByAccountId":{"$in": [<id1>, <id2>, ...]}
    // }`
    wix.common.QueryV2 query = 1;
}

message QuerySiteInvitesResponse {
    repeated SiteInvite invites = 1;
}

message ResendSiteInviteRequest {
    // Invite ID.
    string invite_id = 1;
    // Language of emails to send. Relevant only for recipients that don't currently have a Wix user ID. Default: Site owner's language.
    google.protobuf.StringValue default_email_language = 2 [(.wix.api.pii) = false];
}

message BulkSiteInviteRequest {
    // Role IDs, referred to as policy IDs, to assign to the contributors.
    repeated string policy_ids = 1;
    // Email addresses to which the invites should be sent.
    repeated string emails = 2 [(wix.api.minSize) = 1, (wix.api.maxSize) = 10];
    // Details explaining the purpose of the invite.
    google.protobuf.StringValue invite_purpose = 4;
    // Language of emails to send. Relevant only for recipients that don't currently have a Wix user ID. Default: Site owner's language.
    google.protobuf.StringValue default_email_language = 5 [(.wix.api.pii) = false];
    // Location restriction for the invite.
    LocationRestriction location_restriction = 6;
}

message BulkSiteInviteResponse {
    // Invites that were sent successfully.
    repeated SiteInvite invites = 1;
    // Invites that failed.
    repeated string failed_emails = 2;
}

message AcceptSiteInviteRequest {
    string invite_token = 1;
}

message AcceptSiteInviteResponse {}

message RevokeSiteInviteRequest {
    // Invite ID.
    string invite_id = 1;
}


message RevokeSiteInviteResponse {}

message UpdateSiteInviteRequest {
    string invite_id = 1;
    repeated string policy_ids = 2;
    google.protobuf.StringValue staff_id = 3 [(wix.api.format) = GUID];
    LocationRestriction location_restriction = 4;
}

message LocationRestriction {
    repeated string location_ids = 1 [(wix.api.format) = GUID, (wix.api.maxSize) = 20];
}

message UpdateSiteInviteResponse {}

message ParseSiteInviteTokenRequest {
    string invite_token = 1;
}

message ParseSiteInviteTokenResponse {
    string invite_id = 1;
    string site_id = 2;
    InviteStatus status = 3;
}

message GetContributorLimitRequest { }

message GetContributorLimitResponse {
    ContributorLimitation contributor_limitation = 1;
}

message ContributorLimitation {
    int32 contributor_limit = 1;
    int32 left_invites = 2;
}

// Events being produced by the service
message SiteInviteEvent {
    oneof events {
        // invite created events
        SiteInvite invite_created = 1;
        // invite updated event
        SiteInviteUpdated invite_updated = 2;
        // invite accepted event
        SiteInviteAccepted invite_accepted = 3;
        // invite deleted event
        SiteInviteDeleted invite_deleted = 4;
    }
}

message SiteInviteUpdated {
    // The id of the updated invite
    string invite_id = 1 [(wix.api.format) = GUID];
    // The id of the site in which the invite was updated
    string metasite_id = 2[(wix.api.format) = GUID];
    // A list of fields that have been updated
    repeated InviteFieldUpdated field_updated = 3;
}

message SiteInviteAccepted {
    // The id of the accepted invite
    string invite_id = 1 [(wix.api.format) = GUID];
    // The id of the site in which the invite was accepted
    string metasite_id = 2[(wix.api.format) = GUID];
    // The account which accepted the invite
    google.protobuf.StringValue accepted_by_account_id = 3 [(wix.api.format) = GUID];
}

message SiteInviteDeleted {
    // The id of the deleted invite
    string invite_id = 1 [(wix.api.format) = GUID];
    // The id of the site in which the invite was deleted
    string metasite_id = 2[(wix.api.format) = GUID];
}
