syntax = "proto3";

package usercarts;

import "public_messages.proto";
import "google/protobuf/empty.proto";
import "google/protobuf/wrappers.proto";
import "google/protobuf/duration.proto";  
import "google/protobuf/timestamp.proto";
import "google/api/annotations.proto";

option csharp_namespace = "CMSMicroservice.Protobuf.Protos.UserCarts";

service UserCartsContract
{
    // ============= Admin Methods =============
    
    rpc AddNewUserCart(AddNewUserCartRequest) returns (AddNewUserCartResponse){
        option (google.api.http) = {
            post: "/AddNewUserCart"
            body: "*"
        };
    };
    rpc UpdateUserCart(UpdateUserCartRequest) returns (google.protobuf.Empty){
        option (google.api.http) = {
            put: "/UpdateUserCart"
            body: "*"
        };
    };
    rpc DeleteUserCart(DeleteUserCartRequest) returns (google.protobuf.Empty){
        option (google.api.http) = {
            delete: "/DeleteUserCart"
            body: "*"
        };
    };
    rpc GetUserCart(GetUserCartRequest) returns (GetUserCartResponse){
        option (google.api.http) = {
            get: "/GetUserCart"
        };
    };
    rpc GetAllUserCartsByFilter(GetAllUserCartsByFilterRequest) returns (GetAllUserCartsByFilterResponse){
        option (google.api.http) = {
            get: "/GetAllUserCartsByFilter"
        };
    };
    
    // ============= Customer-specific Methods =============
    
    rpc AddNewUserCartForCustomer(AddNewUserCartForCustomerRequest) returns (AddNewUserCartForCustomerResponse){
        option (google.api.http) = {
            post: "/Customer/AddToCart"
            body: "*"
        };
    };
    rpc UpdateUserCartForCustomer(UpdateUserCartForCustomerRequest) returns (UpdateUserCartForCustomerResponse){
        option (google.api.http) = {
            put: "/Customer/UpdateCart"
            body: "*"
        };
    };
    rpc RemoveUserCartForCustomer(RemoveUserCartForCustomerRequest) returns (RemoveUserCartForCustomerResponse){
        option (google.api.http) = {
            delete: "/Customer/RemoveFromCart"
            body: "*"
        };
    };
    rpc GetCustomerCart(GetUserCartForCustomerRequest) returns (GetUserCartForCustomerResponse){
        option (google.api.http) = {
            get: "/Customer/GetCart"
        };
    };
}
// ============= Admin Messages =============

message AddNewUserCartRequest
{
    int64 product_id = 1;
    int64 user_id = 2;
    int32 count = 3;
}
message AddNewUserCartResponse
{
    int64 id = 1;
}
message UpdateUserCartRequest
{
    int64 id = 1;
    int64 user_cart_id = 11; // Alias for frontend compatibility
    int32 count = 2;
}
message DeleteUserCartRequest
{
    int64 id = 1;
}
message GetUserCartRequest
{
    int64 id = 1;
}
message GetUserCartResponse
{
    int64 id = 1;
    int64 product_id = 2;
    int64 user_id = 3;
    int32 count = 4;
}

// ============= Customer Messages =============

message AddNewUserCartForCustomerRequest
{
    int64 product_id = 1;
    int32 count = 2;
    // user_id will be extracted from JWT token
}
message AddNewUserCartForCustomerResponse
{
    int64 id = 1;
    string message = 2;
    bool success = 3;
}
message UpdateUserCartForCustomerRequest
{
    int64 cart_item_id = 1;
    int32 count = 2;
    // user_id will be extracted from JWT token
}
message UpdateUserCartForCustomerResponse
{
    string message = 1;
    bool success = 2;
}
message RemoveUserCartForCustomerRequest
{
    int64 cart_item_id = 1;
    // user_id will be extracted from JWT token
}
message RemoveUserCartForCustomerResponse
{
    string message = 1;
    bool success = 2;
}
message GetUserCartForCustomerRequest
{
    // user_id will be extracted from JWT token
    // pagination could be added if needed
}
message GetUserCartForCustomerResponse
{
    repeated UserCartItem models = 1;
    int64 total_price = 2;
    int32 total_items_count = 3;
    string message = 4;
}
message UserCartItem
{
    int64 id = 1;
    int64 product_id = 2;
    string product_title = 3;
    string product_short_information = 4;
    string product_short_infomation = 14; // Alias for typo compatibility
    int64 product_price = 5;
    int32 product_discount = 6;
    string product_thumbnail_path = 7;
    int32 count = 8;
    int64 total_item_price = 9;
    google.protobuf.Timestamp created = 10; // Creation timestamp for frontend
}
message GetAllUserCartsByFilterRequest
{
    messages.PaginationState pagination_state = 1;
    google.protobuf.StringValue sort_by = 2;
    GetAllUserCartsByFilterFilter filter = 3;
}
message GetAllUserCartsByFilterFilter
{
    google.protobuf.Int64Value id = 1;
    google.protobuf.Int64Value product_id = 2;
    google.protobuf.Int64Value user_id = 3;
    google.protobuf.Int32Value count = 4;
}
message GetAllUserCartsByFilterResponse
{
    messages.MetaData meta_data = 1;
    repeated GetAllUserCartsByFilterResponseModel models = 2;
}
message GetAllUserCartsByFilterResponseModel
{
    int64 id = 1;
    int64 product_id = 2;
    int64 user_id = 3;
    int32 count = 4;
    string product_title = 5;
    string product_short_infomation = 6;
    int64 product_price = 7;
    int32 product_discount = 8;
    string product_thumbnail_path = 9;
    google.protobuf.Timestamp created = 10;
}


