syntax = "proto3";

package wix.common;

option java_multiple_files = true;
option java_outer_classname = "WixLinkProto";
option java_package = "com.wix.common";

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

//The link object generated by panels in the editor and used by applications in Wix
message WixLink {
    option (.wix.api.decomposition_minimum_fields) = {
        field: "external"
    };
    option (.wix.api.decomposition_minimum_fields) = {
        field: "page"
    };
    option (.wix.api.decomposition_minimum_fields) = {
        field: "anchor"
    };
    option (.wix.api.decomposition_minimum_fields) = {
        field: "dynamic_page"
    };
    option (.wix.api.decomposition_minimum_fields) = {
        field: "document"
    };
    option (.wix.api.decomposition_minimum_fields) = {
        field: "email"
    };
    option (.wix.api.decomposition_minimum_fields) = {
        field: "phone"
    };
    option (.wix.api.decomposition_minimum_fields) = {
        field: "address"
    };
    option (.wix.api.decomposition_minimum_fields) = {
        field: "whats_app"
    };
    option (.wix.api.decomposition_minimum_fields) = {
        field: "tpa_page_link"
    };
    oneof Link {
        ExternalLink external = 1; // External link type
        PageLink page = 2; // Page link type
        AnchorLink anchor = 3; // Anchor link type
        DynamicPageLink dynamic_page = 4; // Dynamic page link type
        DocumentLink document = 5; // Document link type
        EmailLink email = 6; // Email link type
        PhoneLink phone = 7; // Phone link type
        AddressLink address = 8; // Address link type
        WhatsAppLink whats_app = 9; // WhatsApp link type
        TpaPageLink tpa_page = 10; // TPA link type
    }
}

message ExternalLink {
    option (.wix.api.decomposition_minimum_fields) = {
        field: "url"
    };
    //The url of the page
    string url = 1 [(.wix.api.format) = WEB_URL];
    //Where this link should open, supports _self and _blank or any name the user chooses. _self means same page, _blank means new page.
    google.protobuf.StringValue target = 2;
    //rel of link
    repeated LinkRel rel = 3 [(.wix.api.maxSize) = 20, (.wix.api.field_exposure) = PRIVATE];
}

message PageLink {
    option (.wix.api.decomposition_minimum_fields) = {
        field: "page_id"
    };
    //The page id we want from the site
    string page_id = 1;
    //Where this link should open, supports _self and _blank or any name the user chooses. _self means same page, _blank means new page.
    google.protobuf.StringValue target = 2;
    //rel of link
    repeated LinkRel rel = 3 [(wix.api.maxSize) = 20];
}

message AnchorLink {
    option (.wix.api.decomposition_minimum_fields) = {
        field: "anchor_name"
        field: "anchor_data_id"
        field: "page_id"
    };
    //The name of the anchor
    string anchor_name = 1;
    //The data id (from the JSON page) of the anchor that should be used
    string anchor_data_id = 2;
    //The page id we want from the site
    string page_id = 3;
    //rel of link
    repeated LinkRel rel = 4 [(wix.api.maxSize) = 20];
}

message DynamicPageLink {
    option (.wix.api.decomposition_minimum_fields) = {
        field: "router_id"
        field: "inner_route"
        field: "anchor_data_id"
    };
    //The router that handles this link
    string router_id = 1;
    //The path data we'd like
    string inner_route = 2;
    //The data id (from the JSON page) of the anchor that should be used
    google.protobuf.StringValue anchor_data_id = 3;
    //rel of link
    repeated LinkRel rel = 4 [(wix.api.maxSize) = 20];
}

message DocumentLink {
    option (.wix.api.decomposition_minimum_fields) = {
        field: "doc_id"
        field: "name"
    };
    //The id of the document
    string doc_id = 1;
    //The name of the document for download purposes
    google.protobuf.StringValue name = 2;
    //If this document can be indexed by scrapers, default is false
    bool indexable = 3;
}

message EmailLink {
    option (.wix.api.decomposition_minimum_fields) = {
        field: "recipient"
        field: "subject"
        field: "body"
    };
    //The email we will be sending a message to
    string recipient = 1 [(.wix.api.format) = EMAIL];
    //The subject of the email
    google.protobuf.StringValue subject = 2;
    //The body of the email
    google.protobuf.StringValue body = 3;
}

message PhoneLink {
    option (.wix.api.decomposition_minimum_fields) = {
        field: "phone_number"
    };
    //The phone number we want to link to
    string phone_number = 1 [(.wix.api.pii) = true, (.wix.api.format) = PHONE, (.wix.api.maxLength) = 100];
}

message AddressLink {
    option (.wix.api.decomposition_minimum_fields) = {
        field: "address"
    };
    //An address that we can link to
    string address = 1 [(.wix.api.pii) = true];
}

message WhatsAppLink {
    option (.wix.api.decomposition_minimum_fields) = {
        field: "phone_number"
    };
    //The whatsApp phone number we want to connect with
    string phone_number = 1 [(.wix.api.pii) = true, (.wix.api.format) = PHONE];
}

//Link to a TPA page
message TpaPageLink {
    option (.wix.api.decomposition_minimum_fields) = {
        field: "item_type_identifier"
        field: "item_id"
        field: "page_id"
        field: "app_definition_id"
        field: "path"
    };
    //Type of item (e.g. 'wix.stores.sub_pages.product')
    string item_type_identifier = 1;
    //Id of linked item
    string item_id = 2;
    //Id of linked page
    string page_id = 3;
    //Id of app being linked to (AppDefId)
    string app_definition_id = 4;
    //The relativepath of linked page
    string path = 5;
    //rel of link
    repeated LinkRel rel = 6 [(wix.api.maxSize) = 20];
}

//The 'rel' attribute of the link. The rel attribute defines the relationship between a linked resource and the current document.
//Further reading (also about different possible rel types): https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/rel
//Following are the accepted 'rel' types by Wix applications.
enum LinkRel {
    // default (not implemented)
    unknown_link_rel = 0 [(.wix.api.enum_maturity) = NOT_IMPLEMENTED];
    //Indicates that the current document's original author or publisher does not endorse the referenced document.
    nofollow = 1;
    //Instructs the browser to navigate to the target resource without granting the new browsing context access to the document that opened it.
    noopener = 2;
    //No Referer header will be included. Additionally, has the same effect as noopener.
    noreferrer = 3;
    //Indicates a link that resulted from advertisements or paid placements.
    sponsored = 4;
}
