syntax = "proto2";

package maps_adv.geosmb.harmonist.proto.pipeline;

message Error {
    enum ERROR_CODE {
        INVALID_SESSION_ID = 1;
        BAD_FILE_CONTENT = 2;
        MARKUP_ALREADY_SUBMITTED = 3;
        CLIENTS_ALREADY_WERE_IMPORTED = 4;
        VALIDATION_NOT_FINISHED = 5;

        VALIDATION_ERROR = 1000;
    }

    required ERROR_CODE code = 1;
    optional string description = 2;
}

enum PipelineStep {
    PARSING_DATA = 1;
    VALIDATING_DATA = 2;
    IMPORTING_CLIENTS = 3;
}

enum PipelineStepStatus {
    IN_PROGRESS = 1;
    FINISHED = 2;
    FAILED = 3;
}

message FetchPipelineStatus {
    required string session_id = 1;
    required uint64 biz_id = 2;
}

message PipelineStatus {
    required PipelineStep step = 1;
    required PipelineStepStatus step_status = 2;
    oneof step_result {
        string failed_reason = 3;
        PreviewState preview = 4;
        MarkUpValidationResult validation_result = 5;
        ImportClientsResult import_result = 6;
    }
}


message File {
    enum Extension {
        CSV = 1;
        XLSX = 2;
    }
    required bytes content = 1;
    required Extension extension = 2;
}

message CreateClientsInput {
    required uint64 biz_id = 1;
    oneof content {
        string text = 2;
        File file = 3;
    }
}

message CreateClientsOutput {
    required string session_id = 1;
}

message ShowPreviewInput {
    required string session_id = 1;
    required uint64 biz_id = 2;
}

message Row {
    repeated string cells = 1;
}

message PreviewState {
    repeated Row rows = 1;
    optional MarkUp markup = 2;
}

message SubmitMarkUp {
    required string session_id = 1;
    required uint64 biz_id = 2;
    required MarkUp markup = 3;
}

message MarkUp {
    repeated ColumnTypeMap column_type_map = 1;
    required bool ignore_first_line = 2;
    optional string segment = 3;
}

message ColumnTypeMap {
    enum ColumnType {
        DO_NOT_IMPORT = 0;
        FIRST_NAME = 1;
        LAST_NAME = 2;
        PHONE = 3;
        EMAIL = 4;
        COMMENT = 5;
    }

    required ColumnType column_type = 1;
    required uint32 column_number = 2; // starts from 0
}

message MarkUpValidationResult {
    required uint32 valid_clients_amount = 1;
    optional InvalidClientsReport invalid_clients = 2;
}

message InvalidClientsReport {
    required uint32 invalid_clients_amount = 1;
    required string report_link = 2; // link to MDS
}

message ImportClientsInput {
    required string session_id = 1;
    required uint64 biz_id = 2;
}

message ImportClientsResult {
    required uint32 new_clients_amount = 1;
    required uint32 updated_clients_amount = 2;
}
