syntax = "proto3";

package discountproduct;

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.DiscountProduct";

service DiscountProductContract
{
    rpc CreateDiscountProduct(CreateDiscountProductRequest) returns (CreateDiscountProductResponse){
        option (google.api.http) = {
            post: "/CreateDiscountProduct"
            body: "*"
        };
    };
    rpc UpdateDiscountProduct(UpdateDiscountProductRequest) returns (google.protobuf.Empty){
        option (google.api.http) = {
            put: "/UpdateDiscountProduct"
            body: "*"
        };
    };
    rpc DeleteDiscountProduct(DeleteDiscountProductRequest) returns (google.protobuf.Empty){
        option (google.api.http) = {
            delete: "/DeleteDiscountProduct"
            body: "*"
        };
    };
    rpc GetDiscountProductById(GetDiscountProductByIdRequest) returns (GetDiscountProductByIdResponse){
        option (google.api.http) = {
            get: "/GetDiscountProductById"
        };
    };
    rpc GetDiscountProducts(GetDiscountProductsRequest) returns (GetDiscountProductsResponse){
        option (google.api.http) = {
            get: "/GetDiscountProducts"
        };
    };
    
    // Product Image Gallery Operations
    rpc AddDiscountProductImage(AddDiscountProductImageRequest) returns (AddDiscountProductImageResponse){
        option (google.api.http) = {
            post: "/AddDiscountProductImage"
            body: "*"
        };
    };
    rpc UpdateDiscountProductImage(UpdateDiscountProductImageRequest) returns (google.protobuf.Empty){
        option (google.api.http) = {
            put: "/UpdateDiscountProductImage"
            body: "*"
        };
    };
    rpc DeleteDiscountProductImage(DeleteDiscountProductImageRequest) returns (google.protobuf.Empty){
        option (google.api.http) = {
            delete: "/DeleteDiscountProductImage"
            body: "*"
        };
    };
    rpc ReorderDiscountProductImages(ReorderDiscountProductImagesRequest) returns (google.protobuf.Empty){
        option (google.api.http) = {
            put: "/ReorderDiscountProductImages"
            body: "*"
        };
    };
    rpc GetDiscountProductImages(GetDiscountProductImagesRequest) returns (GetDiscountProductImagesResponse){
        option (google.api.http) = {
            get: "/GetDiscountProductImages"
        };
    };
}

// Create Product
message CreateDiscountProductRequest
{
    string title = 1;
    string short_infomation = 2;
    string full_information = 3;
    int64 price = 4;
    int32 max_discount_percent = 5;
    string image_path = 6;
    string thumbnail_path = 7;
    int32 initial_count = 8;
    int32 sort_order = 9;
    bool is_active = 10;
    repeated int64 category_ids = 11;
    ImageFileModel image_file = 12;
    ImageFileModel thumbnail_file = 13;
}

message CreateDiscountProductResponse
{
    int64 product_id = 1;
}

// Update Product
message UpdateDiscountProductRequest
{
    int64 product_id = 1;
    string title = 2;
    string short_infomation = 3;
    string full_information = 4;
    int64 price = 5;
    int32 max_discount_percent = 6;
    string image_path = 7;
    string thumbnail_path = 8;
    int32 sort_order = 9;
    bool is_active = 10;
    repeated int64 category_ids = 11;
    ImageFileModel image_file = 12;
    ImageFileModel thumbnail_file = 13;
}

// Delete Product
message DeleteDiscountProductRequest
{
    int64 product_id = 1;
}

// Get Product By Id
message GetDiscountProductByIdRequest
{
    int64 product_id = 1;
    int64 user_id = 2; // Optional for view count tracking
}

message GetDiscountProductByIdResponse
{
    int64 id = 1;
    string title = 2;
    string short_infomation = 3;
    string full_information = 4;
    int64 price = 5;
    int32 max_discount_percent = 6;
    string image_path = 7;
    string thumbnail_path = 8;
    int32 remaining_count = 9;
    int32 view_count = 10;
    int32 sort_order = 11;
    bool is_active = 12;
    repeated CategoryInfo categories = 13;
    google.protobuf.Timestamp created = 14;
}

message CategoryInfo
{
    int64 id = 1;
    string name = 2;
    string title = 3;
}

// Get Products with Filters
message GetDiscountProductsRequest
{
    google.protobuf.Int64Value category_id = 1;
    google.protobuf.StringValue search_query = 2;
    google.protobuf.Int64Value min_price = 3;
    google.protobuf.Int64Value max_price = 4;
    google.protobuf.BoolValue is_active = 5;
    google.protobuf.BoolValue in_stock = 6;
    int32 page_number = 7;
    int32 page_size = 8;
    google.protobuf.StringValue sort_by = 9;
}

message GetDiscountProductsResponse
{
    messages.MetaData meta_data = 1;
    repeated DiscountProductDto models = 2;
}

message DiscountProductDto
{
    int64 id = 1;
    string title = 2;
    string short_infomation = 3;
    int64 price = 4;
    int32 max_discount_percent = 5;
    string image_path = 6;
    string thumbnail_path = 7;
    int32 remaining_count = 8;
    int32 view_count = 9;
    bool is_active = 10;
    google.protobuf.Timestamp created = 11;
    int32 sale_count = 12;
}

// ===== Product Image Gallery Messages =====

// Add Product Image
message AddDiscountProductImageRequest
{
    int64 discount_product_id = 1;
    string image_path = 2;
    string thumbnail_path = 3;
    google.protobuf.StringValue title = 4;
    google.protobuf.StringValue alt_text = 5;
}

message AddDiscountProductImageResponse
{
    int64 image_id = 1;
}

// Update Product Image
message UpdateDiscountProductImageRequest
{
    int64 id = 1;
    string image_path = 2;
    string thumbnail_path = 3;
    google.protobuf.StringValue title = 4;
    google.protobuf.StringValue alt_text = 5;
    bool is_active = 6;
}

// Delete Product Image
message DeleteDiscountProductImageRequest
{
    int64 id = 1;
}

// Reorder Product Images
message ReorderDiscountProductImagesRequest
{
    int64 discount_product_id = 1;
    repeated int64 image_ids = 2;
}

// Get Product Images
message GetDiscountProductImagesRequest
{
    int64 discount_product_id = 1;
    bool only_active = 2;
}

message GetDiscountProductImagesResponse
{
    repeated DiscountProductImageDto images = 1;
}

message DiscountProductImageDto
{
    int64 id = 1;
    int64 discount_product_id = 2;
    string image_path = 3;
    string thumbnail_path = 4;
    google.protobuf.StringValue title = 5;
    google.protobuf.StringValue alt_text = 6;
    int32 sort_order = 7;
    bool is_active = 8;
}

// File upload model for binary image uploads from BackOffice
message ImageFileModel
{
    bytes file = 1;
    string mime = 2;
    string file_name = 3;
}
