syntax = "proto3";

package discountshoppingcart;

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

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

service DiscountShoppingCartContract
{
    rpc AddToCart(AddToCartRequest) returns (AddToCartResponse){
        option (google.api.http) = {
            post: "/AddToCart"
            body: "*"
        };
    };
    rpc RemoveFromCart(RemoveFromCartRequest) returns (RemoveFromCartResponse){
        option (google.api.http) = {
            delete: "/RemoveFromCart"
            body: "*"
        };
    };
    rpc UpdateCartItemCount(UpdateCartItemCountRequest) returns (UpdateCartItemCountResponse){
        option (google.api.http) = {
            put: "/UpdateCartItemCount"
            body: "*"
        };
    };
    rpc GetUserCart(GetUserCartRequest) returns (GetUserCartResponse){
        option (google.api.http) = {
            get: "/GetUserCart"
        };
    };
    rpc ClearCart(ClearCartRequest) returns (google.protobuf.Empty){
        option (google.api.http) = {
            delete: "/ClearCart"
            body: "*"
        };
    };
}

// Add to Cart
message AddToCartRequest
{
    int64 user_id = 1;
    int64 product_id = 2;
    int32 count = 3;
}

message AddToCartResponse
{
    bool success = 1;
    string message = 2;
}

// Remove from Cart
message RemoveFromCartRequest
{
    int64 user_id = 1;
    int64 product_id = 2;
}

message RemoveFromCartResponse
{
    bool success = 1;
    string message = 2;
}

// Update Cart Item Count
message UpdateCartItemCountRequest
{
    int64 user_id = 1;
    int64 product_id = 2;
    int32 new_count = 3;
}

message UpdateCartItemCountResponse
{
    bool success = 1;
    string message = 2;
}

// Get User Cart
message GetUserCartRequest
{
    int64 user_id = 1;
}

message GetUserCartResponse
{
    repeated CartItemDto items = 1;
    int64 total_price = 2;
    int64 total_discount_amount = 3;
    int64 final_price = 4;
}

message CartItemDto
{
    int64 product_id = 1;
    string product_title = 2;
    string product_image_path = 3;
    int64 unit_price = 4;
    int32 max_discount_percent = 5;
    int32 count = 6;
    int64 total_price = 7;
    int64 discount_amount = 8;
    int64 final_price = 9;
    int32 product_remaining_count = 10;
    google.protobuf.Timestamp created = 11;
}

// Clear Cart
message ClearCartRequest
{
    int64 user_id = 1;
}
