syntax = "proto3";
package wix.dealerBackoffice.api.v1;

import "google/protobuf/wrappers.proto";
option java_package = "com.wix.dealerBackoffice.api.v1";

// FrequencyCaps is an entity containing some criterias (rules) for offer eligibility based on
// past interactions of a user with the offer (or related offers).
// By "interactions" we mean views, clicks, etc. Anything that is collected by deler-events API.
//
// FrequencyCaps can be set per offer or per placement. If set on placement level - it's like a default
// value for all offers in the placement. While offer level FrequencyCaps is like specific value for the
// offer only.
message FrequencyCaps {
  // If this flag is set & true — an offer frequency caps are calculated not separately but together with
  // other offers belonging to same campaign & placement.
  //
  // For example frequencyCaps.views.limit = 5 with `count_with_related_offers` == false
  // means "stop this offer when it was viewed 5 times by this user".
  // While frequencyCaps.views.limit = 5 with `count_with_related_offers` == true
  // means "stop this offer when any of the offers within same campaign & placement
  // were together viewed 5 times by this user".
  google.protobuf.BoolValue count_with_related_offers = 1;

  // Actual limits imposed on the offer. Null if no limits.
  Conditions conditions = 2;

  message Conditions {
    // Max number of total offer VIEW events.
    EventsCountLimit views = 1;
    // Max number of total offer MAIN_CTA clicks.
    EventsCountLimit main_cta_clicks = 2;
    // Max number of total offer SKIP events.
    EventsCountLimit skips = 3;
    // Max number of total offer CLOSE events.
    EventsCountLimit closes = 4;
    // Max number of total offer SHOW_LATER events.
    LastEventLimit show_later = 10;

    enum CountType {
      UNKNOWN = 0;
      TOTAL = 1;
      DAYS = 2;
    }

    // Simple number limit
    message LastEventLimit {
      int32 limit = 1;
    }

    // Limit supporting number count or days aggregation count
    message EventsCountLimit {
      int32 limit = 1;
      CountType type = 2;
    }
  }
}

// Event types supported by frequency caps (equivalent to dealer events API event types
// https://github.com/wix-private/dealer-offer-events/tree/master/packages/dealer-offer-events-api/src/main/proto/wix/dealerOfferEvents/api/v1)
enum FrequencyCapsEventType {
  UNKNOWN = 0;
  VIEW = 1;
  MAIN_CTA_CLICK = 2;
  SKIP = 3;
  UNSKIP = 4;
  CLOSE = 5;
  SHOW_LATER = 6;
}

// List of supported events for a placement
message FrequencyCapsEvents {
  repeated FrequencyCapsEventType events = 1;
}
