syntax = "proto3";

package com.wixpress.metasite.event.api;

import "google/protobuf/wrappers.proto";
import "com/wixpress/metasite/event/api/dto.proto";
import "wix/api/validations.proto";
import "wix/api/entity.proto";
import "wix/api/annotations.proto";

message SiteCreated {
    string origin_template_id = 1 [(wix.api.maxLength) = 36]; // A template identifier (empty if not created from a template).
    string owner_id = 2 [(wix.api.format) = GUID]; // An account id of the owner.
    SiteCreatedContext context = 3; // A context in which meta site was created.
    /*
      A meta site id from which this site was created.

      In case of a creation from a template it's a template id.
      In case of a site duplication ("Save As" in dashboard or duplicate in UM) it's an id of a source site.
    */
    google.protobuf.StringValue origin_meta_site_id = 4 [(wix.api.format) = GUID];
    string site_name = 5 [(wix.api.maxLength) = 20]; // A meta site name (URL slug).
    MetaSite.Namespace namespace = 6; // A namespace.
}

/*
  Hard deletion of the meta site.

  Could not be restored. Therefore it's desirable to cleanup data.
*/
message SiteHardDeleted {
    DeleteContext delete_context = 1; // A deletion context.
}

// Soft deletion of the meta site. Could be restored.
message SiteDeleted {
    DeleteContext delete_context = 1; // A deletion context.
}

// Restoration of the meta site.
message SiteUndeleted {
}

// First publish of a meta site. Or subsequent publish after unpublish.
message SitePublished {
}

message SiteUnpublished {
    repeated string urls = 1 [(wix.api.maxLength) = 4000, (wix.api.maxSize) = 10000]; // A list of URLs previously associated with the meta site.
}

// Site transferred to another user.
message SiteTransferred {
    string old_owner_id = 1 [(wix.api.format) = GUID]; // A previous owner id (user that transfers meta site).
    string new_owner_id = 2 [(wix.api.format) = GUID]; // A new owner id (user that accepts meta site).
}

message SiteMarkedAsTemplate {
}

message SiteMarkedAsWixSite {
}

/*
    Represents a service provisioned a site.
    
    Note on `origin_instance_id`:
    There is no guarantee that you will be able to find a meta site using `origin_instance_id`. 
    This is because of the following scenario:
    
    Imagine you have a template where a third-party application (TPA) includes some stub data,
    such as a product catalog. When you create a site from this template, you inherit this 
    default product catalog. However, if the template's product catalog is modified,
    your site will retain the catalog as it was at the time of site creation. This ensures that 
    your site remains consistent with what you initially received and does not include any 
    changes made to the original template afterward.
    To ensure this, the TPA on the template gets a new instance_id.
*/
message ServiceProvisioned {
    string app_def_id = 1 [(wix.api.maxLength) = 36]; // Either UUID or EmbeddedServiceType.
    string instance_id = 2 [(wix.api.maxLength) = 36]; // Not only UUID. Something here could be something weird.
    string origin_instance_id = 3 [(wix.api.maxLength) = 36]; // An instance id from which this instance is originated.
    google.protobuf.StringValue version = 4 [(wix.api.maxLength) = 500]; // A version.
    google.protobuf.StringValue origin_meta_site_id = 5 [(wix.api.format) = GUID]; // The origin meta site id
}

message ServiceRemoved {
    string app_def_id = 1 [(wix.api.maxLength) = 36]; // Either UUID or EmbeddedServiceType.
    string instance_id = 2 [(wix.api.maxLength) = 36]; // Not only UUID. Something here could be something weird.
    google.protobuf.StringValue version = 3 [(wix.api.maxLength) = 500]; // A version.
}

/* Rename of the site. Meaning, free public url has been changed as well. */
message SiteRenamed {
    string new_site_name = 1 [(wix.api.maxLength) = 20]; // A new meta site name (URL slug).
    string old_site_name = 2 [(wix.api.maxLength) = 255]; // A previous meta site name (URL slug).
}

enum SiteCreatedContext {
    OTHER = 0; // A valid option, we don't expose all reasons why site might be created.
    FROM_TEMPLATE = 1; // A meta site was created from template.
    DUPLICATE_BY_SITE_TRANSFER = 2; // A meta site was created by copying of the transfferred meta site.
    DUPLICATE = 3; // A copy of existing meta site.
    OLD_SITE_TRANSFER = 4; // A meta site was created as a transfferred site (copy of the original), old flow, should die soon.
    FLASH = 5 [deprecated = true];//deprecated A meta site was created for Flash editor.
}

message NamespaceChanged {
    MetaSite.Namespace old_namespace = 1; // A previous namespace.
    MetaSite.Namespace new_namespace = 2; // A new namespace.
}

/*
  Fired in case site URLs were changed in any way: new secondary domain, published, account slug rename, site rename etc.

  This is an internal event, it's not propagated in special events, because it's non-actionable. If you need to keep up
  with sites and its urls, you need to listen to another topic/event. Read about it:

  https://bo.wix.com/wix-docs/rest/meta-site/meta-site---urls-service
*/
message SiteUrlChanged {
}

/*
  Assigned Studio editor
*/
message StudioAssigned {
}

/*
  Unassigned Studio editor
*/
message StudioUnassigned {
}

/*
  Assigned Odeditor
*/
message OdeditorAssigned {
}

/*
  Unassigned Odeditor
*/
message OdeditorUnassigned {
}

/*
  Assigned Picasso editor
*/
message PicassoAssigned {
}

/*
  Unassigned Picasso
*/
message PicassoUnassigned {
}

/*
  Used in case a Virtual Tpa is one of the apps mentioned in one of the payloads.
  A Virtual Tpa represents an embedded service that is in the process of migrating to a ThirdPartyApp.
  It is not persisted on the MetaSite, or in app-container, but it is treated by consumers outside of MetaSite as if it is a provisioned app.
*/
message VirtualTpaMentioned {
  string app_def_id = 1 [(wix.api.maxLength) = 36]; // Either UUID or EmbeddedServiceType.
}

/*
    Used at the end of the deletion flow for both draft sites and when a user deletes a site.
    Consumed by other teams to remove relevant data.
 */
message SitePurgedExternally {
    repeated string app_def_id = 1 [(.wix.api.maxLength) = 2048, (wix.api.maxSize) = 100, deprecated = true, (.wix.api.field_deprecated) = {
        target_removal_date: "2025-04-15"
    }]; // deprecated, use empty event instead
}
