syntax = "proto2";

package maps_adv.billing_proxy.proto.products;

import "google/protobuf/timestamp.proto";
import "maps_adv/billing_proxy/proto/common.proto";


// Product advise request payload
message ProductAdviseInput {
    required common.PlatformType platform = 1;
    required common.CampaignType campaign_type = 2;
    optional uint64 client_id = 3;
    optional uint64 contract_id = 4;
    optional common.CurrencyType currency = 5;
    optional uint64 service_id = 6;
    repeated common.PlatformType additional_platforms = 7;
    repeated common.PlatformType exact_platforms = 8;
}

message Fix {
    enum TimeIntervalType {
        DAILY = 1;
        WEEKLY = 2;
        MONTHLY = 3;
    }
    required TimeIntervalType time_interval = 1;
    optional common.MoneyQuantity OBSOLETE__cost = 2;
    optional string cost = 3;
}

message Cpm {
    optional common.MoneyQuantity OBSOLETE__base_cpm = 1;
    optional string base_cpm = 2;
}

message Billing {
    oneof billing {
        Fix fix = 1;
        Cpm cpm = 2;
    }
}

message ProductVersion {
    required uint64 version = 1;
    required google.protobuf.Timestamp active_from = 2;
    optional google.protobuf.Timestamp active_to = 3;
    required Billing billing = 4;
    optional string min_budget = 5;
    repeated string cpm_filters = 6;
}

// Product info
message ProductInfo {
    required uint64 id = 1;
    required uint64 oracle_id = 2;
    required uint64 service_id = 20;
    required int32 version = 3;
    required string title = 4;
    required string act_text = 5;
    required string description = 6;
    required common.CurrencyType currency = 7;
    required Billing billing = 8;
    required uint32 vat_value = 9; // In 1/100 of percent
    required common.CampaignType campaign_type = 10;
    optional common.PlatformType platform = 11;
    repeated common.PlatformType platforms = 19;
    optional common.MoneyQuantity OBSOLETE__min_budget = 12;
    optional string min_budget = 18;
    required string comment = 13;
    required bool available_for_agencies = 14;
    required bool available_for_internal = 15;
    required google.protobuf.Timestamp active_from = 16;
    optional google.protobuf.Timestamp active_to = 17;
    repeated ProductVersion versions = 21;
    required string type = 22;
}

message ProductsInfo {
    repeated ProductInfo products = 1;
}

message CpmCalculationInput {
    enum AdvRubric {
        COMMON = 1;
        AUTO = 2;
        REALTY = 3;
    }

    enum OrderSize {
        SMALL = 1;
        BIG = 2;
        VERY_BIG = 3;
    }

    enum CreativeType {
        BILLBOARD = 1;
        PIN = 2;
        BANNER = 3;
        TEXT = 4;
        ICON = 5;
        PIN_SEARCH = 6;
        LOGO_AND_TEXT = 7;
        VIA_POINT = 8;
        AUDIO_BANNER = 9;
    }

    // Advertising category
    optional AdvRubric rubric = 1;
    // Targeting query used in campaign
    optional string targeting_query = 2;
    // Campaign creation dt or any other datetime to select product version
    optional google.protobuf.Timestamp dt = 3;
    // Order size (used in Turkey)
    optional OrderSize order_size = 4;
    repeated CreativeType creative_types = 5;
    optional google.protobuf.Timestamp active_from = 6;
    optional google.protobuf.Timestamp active_to = 7;
}

message CpmCalculationCoef {
    enum FieldType {
        CREATIVE = 1;
        RUBRIC = 2;
        TARGETING = 3;
        MONTHLY = 4;
    }

    enum TargetingCriterion {
        AGE = 1;
        GENDER = 2;
        INCOME = 3;
        AUDIENCE = 4;
        SEGMENT = 5;
    }

    required string rate = 1;
    required FieldType field = 2;
    oneof value {
        bool default_value = 3;
        TargetingCriterion targeting_value = 4;
        CpmCalculationInput.AdvRubric rubric_value = 5;
        CpmCalculationInput.CreativeType creative_value = 6;
        uint32 month_value = 7;
    }
    optional google.protobuf.Timestamp active_from = 8;
    optional google.protobuf.Timestamp active_to = 9;
}

message CpmCalculationPeriod {
    required google.protobuf.Timestamp active_from = 1;
    required google.protobuf.Timestamp active_to = 2;
    required string final_cpm = 3;
}

message CpmCalculationResult {
    required common.MoneyQuantity OBSOLETE__cpm = 1;
    required string cpm = 2;
    optional string base_cpm = 3;
    repeated CpmCalculationCoef coefs = 4;
    repeated CpmCalculationPeriod periods = 5;
}

message ServiceIds {
    repeated uint64 service_ids = 1;
}

message ClientBinding {
    required uint64 client_id = 1;
    optional uint64 contract_id = 2;
}

message ClientBindings {
    repeated ClientBinding clients = 1;
}

message CreateProductInput {
    required uint64 oracle_id = 1;
    required string title = 2;
    required string act_text = 3;
    required string description = 4;
    required common.CurrencyType currency = 5;
    required uint32 vat_value = 6; // In 1/100 of percent
    required common.CampaignType campaign_type = 7;
    repeated common.PlatformType platforms = 8;
    required string comment = 9;
    required google.protobuf.Timestamp active_from = 10;
    optional google.protobuf.Timestamp active_to = 11;
    required Billing billing = 12;
    required string min_budget = 13;
    // An array of tags, possible values are:
    //   targeting_type_common, targeting_type_cascade_except_realty,
    //   creative_presence_audio_banner, rubric_name_common,
    //   rubric_name_common_v2, try_order_size_2020
    // For example '{targeting_type_common, rubric_name_common_v2}'
    repeated string cpm_filters = 14;
    required string type = 15;
    required uint64 author_id = 16;
}

message ProductId {
    required uint64 product_id = 1;
}

message UpdateProductInput {
    required string title = 1;
    required string act_text = 2;
    required string description = 3;
    required uint32 vat_value = 4; // In 1/100 of percent
    required string comment = 5;
    repeated ProductVersion versions = 6; // Ignores versions.version
    required uint64 author_id = 7;
}
