syntax = "proto3";

package wix.inventory.api.v1;

import "wix/api/validations.proto";
import "wix/api/annotations.proto";
import "wix/api/entity.proto";
import "google/protobuf/wrappers.proto";
import "google/protobuf/timestamp.proto";
import "wix/inventory/api/v1/preOrderInfo.proto";

option java_package = "com.wix.ecommerce.inventory.api.v1";


message InventoryItemV2 {
    option (wix.api.entity) = {
        fqdn: "wix.stores.v2.inventory"
        app_def_id: "215238eb-22a5-4c36-9e7b-e7c08025e04e"
        segment: USERS
        appendix_files: {
            type: AUTO_VELO
            path: "appendices/velo"
        },
        appendix_files: {
            type: DOCS_CONF
            path: "appendices/docs"
        }
    };

    // Inventory item ID.
    google.protobuf.StringValue id = 1;
    // Deprecated: use productId.
    google.protobuf.StringValue external_id = 2 [(wix.api.readOnly) = true, deprecated = true, (.wix.api.field_deprecated) = {
        replaced_by: "product_id"
        target_removal_date: "2024-12-31"
    }];
    // Product ID.
    google.protobuf.StringValue product_id = 7 [(wix.api.readOnly) = true];
    // Whether quantity is being tracked.
    google.protobuf.BoolValue track_quantity = 3;
    // Variants associated with this inventory item.
    repeated InventoryVariantV2 variants = 4;
    // Last updated timestamp.
    google.protobuf.Timestamp last_updated = 5 [(wix.api.readOnly)=true];
    // Inventory’s unique numeric ID (assigned in ascending order).
    // Primarily for sorting and filtering when crawling all inventories.
    uint64 numericId = 6 [(wix.api.readOnly) = true];
    // Preorder information.
    PreorderInfo preorder_info = 8;
}

message InventoryVariantV2 {
    // Variant ID.
    string variant_id = 1;
    // Whether the product is listed as in stock.
    google.protobuf.BoolValue in_stock = 2;
    // Quantity currently left in inventory.
    google.protobuf.Int32Value quantity = 3 [(wix.api.min) = 0];
    // Whether the variant is available for preorder. When `true`, the variant is out of stock and preorder is enabled on inventory level.
    bool available_for_preorder = 4 [(wix.api.readOnly) = true];
}

message DecrementData {
    oneof id {
        // Inventory item ID.
        string inventory_id = 1 [(wix.api.maxLength) = 36];
        // Deprecated: use productId.
        string external_id = 2 [(wix.api.maxLength) = 36, deprecated = true, (.wix.api.field_deprecated) = {
            replaced_by: "product_id"
            target_removal_date: "2024-12-31"
        }];
        // Product ID.
        string product_id = 5 [(wix.api.maxLength) = 36];
    }
    // Variant ID.
    string variant_id = 3 [(wix.api.format) = GUID];
    // Number to decrement inventory by.
    int32 decrement_by = 4 [(wix.api.min) = 1];
    // Whether the request to decrement the item's inventory was made as part of a purchase that includes preorder items.
    // If true and the item is available for preorder, we allow negative inventory.
    // If false and the item is not available for preorder, we allow regular buy flow (no negative inventory).
    bool preorder_request = 6;
}

message ReasonTypeWrapper {
    enum ReasonType {
        UNKNOWN = 0; // Unknown reason.
        ORDER = 1; // Order related.
        MANUAL = 2; // Manual adjustment.
        REVERT_INVENTORY_CHANGE = 3; // Reverting an inventory change.
    }
}

message IncrementData {
    oneof id {
        // Inventory item ID.
        string inventory_id = 1 [(wix.api.maxLength) = 36];
        // Product ID.
        string product_id = 5 [(wix.api.maxLength) = 36];
    }
    // Variant ID.
    string variant_id = 3 [(wix.api.format) = GUID];
    // Number to increment inventory by.
    int32 increment_by = 4 [(wix.api.min) = 1];
}