syntax = "proto2";

package maps_adv.adv_store.proto.campaign;

import "google/protobuf/timestamp.proto";
import "maps_adv/adv_store/api/proto/action.proto";
import "maps_adv/adv_store/api/proto/billing.proto";
import "maps_adv/adv_store/api/proto/campaign_status.proto";
import "maps_adv/adv_store/api/proto/creative.proto";
import "maps_adv/adv_store/api/proto/discount.proto";
import "maps_adv/adv_store/api/proto/placing.proto";
import "maps_adv/common/proto/campaign.proto";

message Platform {
    enum Enum {
        NAVI = 1;
        MAPS = 2;
        METRO = 3;
    }
}

message PublicationEnv {
    enum Enum {
        PRODUCTION = 1;
        DATA_TESTING = 2;
    }
}

message WeekScheduleItem {
    optional uint32 start = 1;  // minutes from the start of a week
    optional uint32 end = 2;  // minutes from the start of a week
}

message Rubric {
    enum Enum {
        COMMON = 1;
        AUTO = 2;
        REALTY = 3;
    }
}

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

message OverviewPosition {
    enum Enum {
        START = 1;
        FINISH = 2;
        ALL = 3;
    }
}

message VerificationData {
    // Used by export, currently supports 'dcm', 'weborama' and 'sizmek'
    required string platform = 1;
    map<string, string> params = 2;
}

message CampaignSettings {
    optional string custom_page_id = 1;
    optional OverviewPosition.Enum overview_position = 2;

    // Will be used in cpm calculation instead of campaign creation datetime
    optional google.protobuf.Timestamp forced_product_version_datetime = 3;

    repeated VerificationData verification_data = 4;
    optional bool auto_prolongation = 5;
}

message CampaignData {  // for POST
    required string name = 1;
    required uint64 author_id = 2;
    optional google.protobuf.Timestamp created_datetime = 25;
    repeated PublicationEnv.Enum publication_envs = 3;
    required maps_adv.common.proto.campaign.CampaignType.Enum campaign_type = 4;
    required campaign_status.CampaignStatus.Enum status = 5;
    required google.protobuf.Timestamp start_datetime = 6;
    required google.protobuf.Timestamp end_datetime = 7;
    required string timezone = 8;
    required billing.Billing billing = 9;
    required placing.Placing placing = 10;

    repeated Platform.Enum platforms = 11;
    repeated creative.Creative creatives = 12;
    repeated action.Action actions = 13;

    // optional
    repeated WeekScheduleItem week_schedule = 16;
    optional string comment = 18 [default = ""];
    optional uint32 user_display_limit = 19;
    optional uint32 user_daily_display_limit = 20;
    optional string targeting = 21;
    optional Rubric.Enum rubric = 22;
    optional OrderSize.Enum order_size = 26;
    oneof order {
       uint64 order_id = 17;
       uint64 manul_order_id = 23;
    }
    repeated discount.Discount discounts = 24;
    optional google.protobuf.Timestamp datatesting_expires_at = 27;
    repeated uint64 moderation_verdicts = 28;
    optional CampaignSettings settings = 29;
    optional uint64 product_id = 30;
}

message Campaign {
    required uint64 id = 1;
    required CampaignData data = 2;
}

message CampaignExport {
    required uint64 id = 1;
    repeated PublicationEnv.Enum publication_envs = 2;
    required maps_adv.common.proto.campaign.CampaignType.Enum campaign_type = 3;
    required placing.Placing placing = 4;

    repeated Platform.Enum platforms = 5;
    repeated creative.Creative creatives = 6;
    repeated action.Action actions = 7;

    optional uint64 order_id = 8;
    optional uint32 user_display_limit = 9;
    optional uint32 user_daily_display_limit = 10;
    optional string targeting = 11;
    optional string display_probability = 12;
    optional uint32 display_chance = 13;
    optional CampaignSettings settings = 14;
    optional uint64 total_daily_display_limit = 15;
    // "Today" according to campaign's timezone
    optional uint64 total_display_minutes_today = 16;
    optional uint64 total_display_minutes_left_today = 17;
    optional string timezone = 18;
    // `cost` is either CPM or CPA, discount-ajusted, used only for sorting
    optional float cost = 19;
    optional google.protobuf.Timestamp paid_till = 20;
    optional uint64 total_daily_action_limit = 21;
}

message CampaignExportList {
    repeated CampaignExport campaigns = 1;
}


message CampaignConsumedUpdate {
    required uint64 campaign_id = 1;
    required billing.Money budget = 2;
    required billing.Money daily_budget = 3;
}

message CampaignsConsumedUpdate {
    repeated CampaignConsumedUpdate campaigns = 1;
    required google.protobuf.Timestamp processed_at = 2;
}

message CampaignPaidTillChangeInput {
    optional google.protobuf.Timestamp paid_till = 1;
}
