syntax = "proto3";

package wix.devcenter.apps.dependencies.v2.upstream.wix.common;

option java_multiple_files = true;
option java_package = "com.wixpress.devcenter.apps.dependencies.v2.upstream.wix.common";

import "google/protobuf/wrappers.proto";
import "wix/api/validations.proto";
import "wix/api/annotations.proto";
import "wix/api/errors.proto";

message BulkActionMetadata {
    option (.wix.api.decomposite_of) = "wix.commons.v2.BulkActionMetadata";
    option (.wix.api.decomposition_minimum_fields) = {
        field: "total_successes"
        field: "total_failures"
        field: "undetailed_failures"
    };
    // Number of items that were successfully processed.
    int32 total_successes = 1 [(.wix.api.min) = 0];
    // Number of items that couldn't be processed.
    int32 total_failures = 2 [(.wix.api.min) = 0];
    // Number of failures without details because detailed failure threshold was exceeded.
    int32 undetailed_failures = 3 [(.wix.api.min) = 0];
}

message ItemMetadata {
    option (.wix.api.decomposite_of) = "wix.commons.v2.ItemMetadata";
    option (.wix.api.decomposition_minimum_fields) = {
        field: "id"
        field: "original_index"
        field: "success"
        field: "error"
    };
    // Item ID. Provided only whenever possible. For example, `itemId` can't be provided when item creation has failed.
    google.protobuf.StringValue id = 1 [(.wix.api.format) = GUID];
    // Index of the item within the request array. Allows for correlation between request and response items.
    int32 original_index = 2 [(.wix.api.min) = 0];
    // Whether the requested action for this item was successful. When `false`, the `error` field is returned.
    bool success = 3;
    // Details about the error in case of failure.
    .wix.api.ApplicationError error = 4;
}

enum BulkActionType {
    UNKNOWN_ACTION_TYPE = 0 [(.wix.api.enum_maturity) = NOT_IMPLEMENTED];
    INSERT = 1;
    UPDATE = 2;
    DELETE = 3;
}

/*

Example for using it in your service:

message BulkOrderResult {
    option (.wix.api.decomposite_of) = "wix.commons.v2.BulkOrderResult";
    ItemMetadata item_metadata = 1;
    Order item = 2;
}

message BulkArchiveOrdersResponse {
    option (.wix.api.decomposite_of) = "wix.commons.v2.BulkArchiveOrdersResponse";
    repeated BulkOrderResult results = 1;
    BulkActionMetadata bulk_action_metadata = 2;
}

*/
