syntax = "proto2";

package maps_adv.geosmb.clients.facade.proto.facade;

import "google/protobuf/timestamp.proto";

message Paging {
    required uint32 offset = 1;
    required uint32 limit = 2;
}

message PagingOutput {
    required uint32 total = 1;
    required uint32 offset = 2;
    required uint32 limit = 3;
}

enum Currency {
    RUB = 1;
    KZT = 2;
    BYN = 3;
    TRY = 4;
    USD = 5;
    EUR = 6;
}

message Cost {
    required Currency currency = 1;
    required string cost = 2; // В формате 000.00
}

message OrganizationsWithCouponsRequest {
    optional Paging paging = 1; // default offset=0 limit=1000
}

message OrganizationsWithCouponsResponse {
    message OrganizationWithCoupons {
        required string biz_id = 1;
        required string permalink = 2;
        required string showcase_url = 3;
    }

    repeated OrganizationWithCoupons organizations_list = 1;
}

message CouponsStatusesListRequest {
    repeated string items_ids_list = 1;
}

enum CouponStatus {
    NOT_RUNNING_YET = 1;
    RUNNING = 2;
    FINISHED = 3;
}

message CouponsStatusesListResponse {
    message CouponStatusInfo {
        required string biz_id = 1;
        required string item_id = 2;
        required CouponStatus status = 3;
    }

    repeated CouponStatusInfo coupons_statuses_list = 1;
}

message LoyaltyItemsListForSnapshotRequest {
    required Paging paging = 1;
}

message LoyaltyItemsListForSnapshotResponse {
    message LoyaltyItemForSnapshot {
        required uint64 client_id = 1;
        required google.protobuf.Timestamp issued_at = 2;
        required uint64 id = 3;
        required string type = 4;
        required string data = 5; // Serialized json
    }

    repeated LoyaltyItemForSnapshot items_list = 1;
    required PagingOutput paging = 2;
}

message OrganizationsWithBookingRequest {
    optional Paging paging = 1;
}

message OrganizationsWithBookingResponse {
    message OrganizationWithBooking {
        required string biz_id = 1;
        required string permalink = 2;
        required string booking_url = 3;
    }

    repeated OrganizationWithBooking organizations_list = 1;
}

enum CouponModerationStatus {
    IN_REVIEW = 1;
    IN_APPROVED = 2;
    IN_REJECTED = 3;
}

enum CouponDistribution {
    PUBLIC = 1;
    PRIVATE_FOR_SEGMENTS = 2;
    PRIVATE_BY_LINK = 3;
}

message BusinessCouponsForSnapshotRequest {
    required Paging paging = 1;
}

enum CouponCoverType {
    DEFAULT = 1;
    SQUARE = 2;
    SMALL_SQUARE = 3;
    HORIZONTAL = 4;
    VERTICAL = 5;
    LOGO = 6;
}

message CouponCoverTemplate {
    // Шаблон ссылки на обложку
    required string url_template = 1;
    // Поддерживаемые алиасы
    repeated string aliases = 2;
    // Тип обложки
    required CouponCoverType type = 3;
}

message BusinessCouponsForSnapshotResponse {
    message CouponService {
        required string service_id = 1;
        required int32 level = 2;
        required Cost price = 3;
        required string name = 4;
        required int32 duration = 5;
    }

    message CouponItemForSnapshot {
        required uint64 biz_id = 1;
        required uint64 item_id = 2;
        required string title = 3;
        repeated CouponService services = 4;
        optional string products_description = 5;
        required Cost price = 6;
        required uint32 discount = 7;
        required Cost discounted_price = 8;
        required google.protobuf.Timestamp start_date = 9;
        required google.protobuf.Timestamp get_until_date = 10;
        required google.protobuf.Timestamp end_date = 11;
        required CouponDistribution distribution = 12;
        required CouponModerationStatus moderation_status = 13;
        required bool published = 14;
        required bool payments_enabled = 15;
        optional string conditions = 16;
        optional string creator_login = 17;
        optional string creator_uid = 18;
        required google.protobuf.Timestamp created_at = 19;
        repeated CouponCoverTemplate cover_templates = 20;
        optional string coupon_showcase_url = 21;
        required string meta = 22; // Serialized json
    }

    repeated CouponItemForSnapshot items_list = 1;
    required PagingOutput paging = 2;
}


message CouponsWithSegmentsInput {
    required Paging paging = 1;
}


enum SegmentType {
    UNKNOWN = 0;
    REGULAR = 1;
    ACTIVE = 2;
    LOST = 3;
    NO_ORDERS = 4;
    UNPROCESSED_ORDERS = 5;
    PROSPECTIVE = 6;
    LOYAL = 7;
    DISLOYAL = 8;
    MISSED_LAST_CALL = 9;
    SHORT_LAST_CALL = 10;
}

message CouponsWithSegmentsOutput {
    enum CouponType {
        FREE = 1;
        SERVICE = 2;
    }

    message Coupon {
        required uint64 id = 1;
        required CouponType type = 2;
        repeated SegmentType segments = 3;
        oneof discount {
            Cost cost_discount = 4;
            uint32 percent_discount = 5;
        }
    }

    message Business {
        required uint64 biz_id = 1;
        repeated Coupon coupons = 2;
    }

    repeated Business businesses = 1;
}

message FetchCouponPromotionsInput {
    required Paging paging = 1;
}

message FetchCouponPromotionsOutput {
    repeated CouponPromotionItem promotions = 1;
    required PagingOutput paging = 2;
}

message CouponPromotionItem {
    required uint64 advert_id = 1;
    required uint64 coupon_id = 2;
    optional uint64 biz_id = 3;
    required string name = 4;
    required google.protobuf.Timestamp date_from = 5;
    required google.protobuf.Timestamp date_to = 6;
    required string description = 7;
    required string announcement = 8;
    required string image_url = 9;
    required string coupon_url = 10;
}
