syntax = "proto3";

package com.wixpress.invites.api;

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

message AccountInvite {
    option (.wix.api.entity) = {
        fqdn: "wix.identity.invites.v1.account_invite"
        appendix_files: {
            type: AUTO_VELO
            path: "appendices/velo/account-invite"
        }
        appendix_files: {
            type: DOCS_CONF
            path: "appendices/docs"
        }
        segment: USERS
    };
    // Invite ID.
    string id = 1 [(wix.api.format) = GUID, (wix.api.readOnly) = true];
    // Account ID.
    string account_id = 2 [(wix.api.format) = GUID, (wix.api.readOnly) = true];
    // Email address where the invite was sent.
    string email = 3 [(wix.api.format) = EMAIL, (wix.api.pii) = true];
    // Deprecated. Use `policyIds`.
    string role = 4[deprecated = true];
    // Deprecated. Use `inviterAccountId`.
    string inviter_id = 5 [deprecated = true, (wix.api.readOnly) = true];
    /* Invite status.  
    
    Supported values:  
    - **Pending:** The invite has been sent and is valid, waiting for the user's response.
    - **Used:** The invite has been accepted.
    - **Deleted:** The invite has been deleted or revoked.
    - **Declined:** The user has declined the invite.
    - **Expired:** The invite has expired without being accepted.
    */
    InviteStatus status = 6;
    // Link to accept the invite.
    string accept_link = 7;
    // Inviting account ID.
    string inviter_account_id = 8 [(wix.api.format) = GUID, (wix.api.readOnly) = true];
    // Account ID that accepted the invite. Populated only once the invite is accepted.
    google.protobuf.StringValue accepted_by_account_id = 9 [(wix.api.format) = GUID, (wix.api.readOnly) = true];
    // Date the invite was created.
    google.protobuf.Timestamp date_created = 10;
    // Role IDs included in the invite.
    repeated string policy_ids = 11;
    // Date the invite was last updated.
    google.protobuf.Timestamp date_updated = 12;
    // Assets the users are invited to join. 
    repeated com.wixpress.authorization.invite.service.InviteResourceAssignment assignments = 13;
    // Brand domain.
    google.protobuf.StringValue brand_domain = 14[(wix.api.field_exposure) = INTERNAL];
    // Invite expiration date.
    google.protobuf.Timestamp expiration_date = 15;
}

message SiteInvite {
    option (.wix.api.entity) = {
        fqdn: "wix.identity.invites.v1.site_invite"
        appendix_files: {
            type: AUTO_VELO
            path: "appendices/velo/site-invite"
        }
        appendix_files: {
            type: DOCS_CONF
            path: "appendices/docs"
        }
        segment: USERS
    };
    // Invite ID.
    string id = 1 [(wix.api.format) = GUID, (wix.api.readOnly) = true];
    // Site ID the user is invited to as a collaborator.
    string site_id = 2 [(wix.api.format) = GUID, (wix.api.readOnly) = true];
    // Email address where the invite was sent.
    string email = 3 [(wix.api.format) = EMAIL, (wix.api.pii) = true];
    // Role IDs included in the invite.
    repeated string policy_ids = 4;
    // Deprecated. Use `inviterAccountId`.
    string inviter_id = 5 [deprecated = true, (wix.api.readOnly) = true];
    /* Invite Status.

    Supported values:  
    - **Pending:** The invite has been sent and is valid, waiting for the user's response.
    - **Used:** The invite has been accepted.
    - **Deleted:** The invite has been deleted or revoked.
    - **Declined:** The user declined the invite.
    - **Expired:** The invite has expired without being accepted.
    */
    InviteStatus status = 6;
    // Link to accept the invite.
    string accept_link = 7;
    // Inviting account ID.
    string inviter_account_id = 8 [(wix.api.format) = GUID, (wix.api.readOnly) = true];
    // Account ID that accepted the invite. Populated only once the invite is accepted.
    google.protobuf.StringValue accepted_by_account_id = 9 [(wix.api.format) = GUID, (wix.api.readOnly) = true];
    // Date the invite was created.
    google.protobuf.Timestamp date_created = 10;
    // User's Wix Bookings staff ID, if relevant.
    google.protobuf.StringValue staff_id = 11 [(wix.api.format) = GUID];
    // Brand domain.
    google.protobuf.StringValue brand_domain = 12[(wix.api.field_exposure) = INTERNAL];
    // Optional field representing the purpose of the invite
    google.protobuf.StringValue invite_purpose = 13[(wix.api.field_exposure) = INTERNAL];
    // Invite expiration date
    google.protobuf.Timestamp expiration_date = 14;
    // Location ids included in the invite
    repeated string location_ids = 15 [(wix.api.format) = GUID, (wix.api.readOnly) = true, (wix.api.maxSize) = 20];
    // A set of capability keys representing the actions that the caller is allowed
    // to perform on this specific contributor. This field is calculated based on the
    // identity of the request sender and may differ between callers.
    repeated string caller_capabilities = 16 [(wix.api.maxSize) = 20, (wix.api.maxLength ) = 20];
}

message AppWebInvite {
    option (.wix.api.entity) = {
        fqdn: "wix.identity.invites.v1.app_web_invite"
        appendix_files: {
            type: AUTO_VELO
            path: "appendices/velo/app-invite"
        };
        segment: USERS
    };
    string id = 1 [(wix.api.format) = GUID, (wix.api.readOnly) = true];
    com.wixpress.authorization.invite.service.AppInvite invite_data = 2 [(wix.api.readOnly) = true];
    string accept_link = 3 [(wix.api.format) = WEB_URL, (wix.api.readOnly) = true];
}

// Invite status stating whether the invite was accepted, waiting to be accepted, deleted etc..
enum InviteStatus {
    Pending = 0;
    Used = 1;
    Deleted = 2;
    Declined = 3;
    Expired = 4;
}

message InviteFieldUpdated {
    oneof update {
        // The status updated event
        InviteStatusUpdated status_update = 2;
        // Roles update event
        InviteRoleAssignmentsUpdated role_assignments_update = 3;
    }
}

message InviteStatusUpdated {
    // the new status of the invite
    string to_status = 1;
    // The date at which this update occurred
    google.protobuf.Timestamp date_updated = 2;
}

message InviteRoleAssignmentsUpdated {
    // The new assignments of the invite
    repeated com.wixpress.authorization.invite.service.InviteResourceAssignment to_assignments = 1;
}
