/// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

syntax = "proto2";

package components.feed.core.proto.ui.action;

option optimize_for = LITE_RUNTIME;

import "components/feed/core/proto/ui/action/feed_action_payload.proto";
import "components/feed/core/proto/wire/action_payload.proto";
import "components/feed/core/proto/wire/content_id.proto";
import "components/feed/core/proto/wire/data_operation.proto";

option java_package = "org.chromium.components.feed.core.proto.ui.action";
option java_outer_classname = "FeedActionProto";

// Specification of an action to be taken within the feed.
message FeedAction {
  extend FeedActionPayload {
    optional FeedAction feed_action_extension = 192348469;
  }

  // The metadata, which is used by the client to update the client UI in
  // real-time.
  optional FeedActionMetadata metadata = 1;

  reserved 2;  // deprecated fields
}

// Metadata needed by the host to handle the action.
// Next Id: 19
message FeedActionMetadata {
  // The type of action, used by the host to perform any custom logic needed for
  // a specific type of action.
  enum Type {
    UNKNOWN = 0;
    OPEN_URL = 1;
    OPEN_URL_INCOGNITO = 2;
    OPEN_URL_NEW_WINDOW = 3;
    OPEN_CONTEXT_MENU = 4;
    // Dismiss retained on the client and sent with requests. This information
    // should not be persisted to server-side storage as this experience is
    // intended for signed-out users or ones with WAA disabled.
    DISMISS_LOCAL = 5;
    // Dismiss logged on the server for signed-in users with WAA enabled.
    DISMISS = 11;
    // Note that the data required to download content is not on the action, but
    // rather the content. This is intentionally done to avoid sending multiple
    // copies of the same data, which could potentially be multiple long
    // strings.
    DOWNLOAD = 6;
    OPEN_URL_NEW_TAB = 7;
    LEARN_MORE = 8;
    VIEW_ELEMENT = 12;
    HIDE_ELEMENT = 13;
    SHOW_TOOLTIP = 14;
    NOT_INTERESTED_IN = 15;
    SEE_SUGGESTED_SITES = 16;
    SEND_FEEDBACK = 17;
    MANAGE_INTERESTS = 18;
    reserved 9, 10;  // Deprecated
  }
  optional Type type = 1;

  oneof data {
    // The data needed by the client to open the url for any OPEN_URL action
    // including OPEN_URL_INCOGNITO and OPEN_URL_NEW_WINDOW.
    OpenUrlData open_url_data = 2;

    // The data needed by the Stream to open a context menu.
    OpenContextMenuData open_context_menu_data = 3;

    // The data needed by the Stream to perform a dismiss.
    DismissData dismiss_data = 4;

    // The data needed by the Stream to handle the not interested action.
    NotInterestedInData not_interested_in_data = 6;

    // The data needed by the Stream to render a tooltip.
    TooltipData tooltip_data = 8;
  }
  // The type of element this action is bounded on.
  enum ElementType {
    UNKNOWN_ELEMENT_TYPE = 0;
    CARD_LARGE_IMAGE = 1;
    CARD_SMALL_IMAGE = 2;
    INTEREST_HEADER = 3;
    TOOLTIP = 4;
  }
  // Used by the host to perform Basic logging for views and clicks.
  // This should be an ElementType.getNumber() but since proto lite doesn't
  // handle when it gets added to, we need it to be an int instead of an enum
  optional int32 element_type_value = 9;

  reserved 5, 7;
}

// Data needed by the host to handle an OPEN_URL action.
message OpenUrlData {
  // The Url to open.
  optional string url = 1;
  // If populated, the client will attempt to recod all pending actions before
  // opening the url. Once this finishes, the client will attach to the url its
  //  latest frequency token as the value of this query param.
  optional string consistency_token_query_param_name = 2;
  // The content ID that was interacted with to cause a URL open.
  optional feedwire1.ContentId content_id = 3;
  // Roundtripped server data on a per-action level.
  optional feedwire1.ActionPayload payload = 4;
}

// Data needed by Stream to open a context menu.
message OpenContextMenuData {
  repeated LabelledFeedActionData context_menu_data = 1;
}

// Data needed by Stream to perform a dismiss.
message DismissData {
  // The ContentId needed by the server to suppress reshowing the dismissed
  // content. This will usually be the ContentId of the card which holds the
  // content, not the ContentId of the content itself.
  optional feedwire1.ContentId content_id = 1;

  // The DataOperations which are needed to actually perform the dismiss on the
  // client. This is typically a singleton list of a remove operation on the
  // Cluster that the content belongs to.
  repeated feedwire1.DataOperation data_operations = 2;

  // Data used by the client to show a confirmation message with option to undo.
  // This confirmation and undo option will only appear if the UndoAction is
  // present and the client can handle this capability.
  optional UndoAction undo_action = 3;
  // Roundtripped server data on a per-action level.
  optional feedwire1.ActionPayload payload = 4;
}

// Data needed by the client to handle the not interested action.
message NotInterestedInData {
  // Data used by the client to show a confirmation message with option to undo.
  // This confirmation and undo option will only appear if the UndoAction is
  // present and the client can handle this capability.
  optional UndoAction undo_action = 1;
  // The data needed by Stream to preform the dismiss.
  repeated feedwire1.DataOperation data_operations = 2;
  // Roundtripped server data on a per-action level.
  optional feedwire1.ActionPayload payload = 3;
  enum RecordedInterestType {
    UNKNOWN_INTEREST_TYPE = 0;
    TOPIC = 1;
    SOURCE = 2;
  }
  // The type of NotInterested Action that was performed.
  // This should be an RecordedInterestType.getNumber() but since proto lite
  // doesn't handle when it gets added to, we need it to be an int instead of
  // an enum
  optional int32 interest_type_value = 5;

  reserved 4;
}

// Data used by the client to show a confirmation message with an action to
// reverse it.
message UndoAction {
  // The string shown to the user that confirms the action was just taken.
  optional string confirmation_label = 1;
  // The string that labels that option to reverse the action. Defaults to
  // "Undo" if not sent.
  optional string undo_label = 2;
}

// The data needed by the Stream to render a tooltip.
message TooltipData {
  optional string label = 1;
  optional string accessibility_label = 2;
  enum FeatureName {
    // No tooltip will render if the FeatureName is UNKNOWN.
    UNKNOWN = 0;
    CARD_MENU = 1;
  }
  optional FeatureName feature_name = 3;
  // The infromation for where to offset the arrow from the referenced view.
  optional Insets insets = 4;
}

// The information for where to offset the tooltip arrow from the referenced
// view. The host will decide if the tooltip is above or below the view and this
// inset data changes the y coordinate of the tooltip arrow. For example, if top
// inset is 5 and the tooltip is shown above the view, then the tooltip will
// have its point of the arrow horizontally centered 5 dp below the top of the
// referenced view. If bottom inset is 5 and the tooltip is shown below the
// view, then the tooltip will have its point of the arrow horizontally centered
// 5 dp above the bottom of the referenced view. If no inset is set then the
// tooltip will show either directly above/below the referenced view.
message Insets {
  optional int32 top = 1;
  optional int32 bottom = 2;
}

// FeedActionMetadata with a label to show in a context menu.
message LabelledFeedActionData {
  optional string label = 1;
  optional FeedActionPayload feed_action_payload = 2;
}
