syntax = "proto3";

package package;

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

service PackageContract
{
    rpc CreateNewPackage(CreateNewPackageRequest) returns (CreateNewPackageResponse){
        option (google.api.http) = {
            post: "/CreateNewPackage"
            body: "*"
        };
    };
    rpc UpdatePackage(UpdatePackageRequest) returns (google.protobuf.Empty){
        option (google.api.http) = {
            put: "/UpdatePackage"
            body: "*"
        };
    };
    rpc DeletePackage(DeletePackageRequest) returns (google.protobuf.Empty){
        option (google.api.http) = {
            delete: "/DeletePackage"
            body: "*"
        };
    };
    rpc GetPackage(GetPackageRequest) returns (GetPackageResponse){
        option (google.api.http) = {
            get: "/GetPackage"
            
        };
    };
    rpc GetAllPackageByFilter(GetAllPackageByFilterRequest) returns (GetAllPackageByFilterResponse){
        option (google.api.http) = {
            get: "/GetAllPackageByFilter"
            
        };
    };
    
    rpc GetUserPackageStatus(GetUserPackageStatusRequest) returns (GetUserPackageStatusResponse){
        option (google.api.http) = {
            get: "/GetUserPackageStatus"
        };
    };
    
    // ============= Customer-specific Methods =============
    
    rpc GetCustomerPackages(GetCustomerPackagesRequest) returns (GetCustomerPackagesResponse){
        option (google.api.http) = {
            get: "/Customer/GetPackages"
        };
    };
    rpc GetCustomerPackageDetails(GetCustomerPackageDetailsRequest) returns (GetCustomerPackageDetailsResponse){
        option (google.api.http) = {
            get: "/Customer/GetPackageDetails"
        };
    };
    rpc CustomerPurchasePackage(CustomerPurchasePackageRequest) returns (CustomerPurchasePackageResponse){
        option (google.api.http) = {
            post: "/Customer/PurchasePackage"
            body: "*"
        };
    };
    rpc CustomerVerifyPackagePurchase(CustomerVerifyPackagePurchaseRequest) returns (CustomerVerifyPackagePurchaseResponse){
        option (google.api.http) = {
            post: "/Customer/VerifyPackagePurchase"
            body: "*"
        };
    };
    rpc GetCustomerPurchaseHistory(GetCustomerPurchaseHistoryRequest) returns (GetCustomerPurchaseHistoryResponse){
        option (google.api.http) = {
            get: "/Customer/GetPurchaseHistory"
        };
    };
}
message CreateNewPackageRequest
{
    string title = 1;
    string description = 2;
    string image_path = 3;
    int64 price = 4;
    BoostCardFileModel image_file = 5;
    int32 sort_order = 6;
    bool is_active = 7;
    bool is_base_package = 8;
    bool supports_daya_purchase = 9;
    bool supports_direct_purchase = 10;
    int64 activation_fee = 11;
    double discount_multiplier = 12;
    double magic_wallet_multiplier = 13;
    int32 max_balances_per_leg = 14;
    int32 max_network_level = 15;
    int64 magic_wallet_max_deposit = 16;
    int64 magic_wallet_max_credit = 17;
    repeated int64 feature_ids = 18;
}
message CreateNewPackageResponse
{
    int64 id = 1;
}
message UpdatePackageRequest
{
    int64 id = 1;
    string title = 2;
    string description = 3;
    string image_path = 4;
    int64 price = 5;
    BoostCardFileModel image_file = 6;
    int32 sort_order = 7;
    bool is_active = 8;
    bool is_base_package = 9;
    bool supports_daya_purchase = 10;
    bool supports_direct_purchase = 11;
    int64 activation_fee = 12;
    double discount_multiplier = 13;
    double magic_wallet_multiplier = 14;
    int32 max_balances_per_leg = 15;
    int32 max_network_level = 16;
    int64 magic_wallet_max_deposit = 17;
    int64 magic_wallet_max_credit = 18;
    repeated int64 feature_ids = 19;
}
message DeletePackageRequest
{
    int64 id = 1;
}
message GetPackageRequest
{
    int64 id = 1;
}
message GetPackageResponse
{
    int64 id = 1;
    string title = 2;
    string description = 3;
    string image_path = 4;
    int64 price = 5;
    int32 sort_order = 6;
    bool is_active = 7;
    bool is_base_package = 8;
    bool supports_daya_purchase = 9;
    bool supports_direct_purchase = 10;
    int64 activation_fee = 11;
    double discount_multiplier = 12;
    double magic_wallet_multiplier = 13;
    int32 max_balances_per_leg = 14;
    int32 max_network_level = 15;
    int64 magic_wallet_max_deposit = 16;
    int64 magic_wallet_max_credit = 17;
    repeated int64 feature_ids = 18;
}
message GetAllPackageByFilterRequest
{
    messages.PaginationState pagination_state = 1;
    google.protobuf.StringValue sort_by = 2;
    GetAllPackageByFilterFilter filter = 3;
}
message GetAllPackageByFilterFilter
{
    google.protobuf.Int64Value id = 1;
    google.protobuf.StringValue title = 2;
    google.protobuf.StringValue description = 3;
    google.protobuf.StringValue image_path = 4;
    google.protobuf.Int64Value price = 5;
}
message GetAllPackageByFilterResponse
{
    messages.MetaData meta_data = 1;
    repeated GetAllPackageByFilterResponseModel models = 2;
}
message GetAllPackageByFilterResponseModel
{
    int64 id = 1;
    string title = 2;
    string description = 3;
    string image_path = 4;
    int64 price = 5;
    int32 sort_order = 6;
    bool is_active = 7;
    bool is_base_package = 8;
    bool supports_daya_purchase = 9;
    bool supports_direct_purchase = 10;
    int64 activation_fee = 11;
    double discount_multiplier = 12;
    double magic_wallet_multiplier = 13;
    int32 max_balances_per_leg = 14;
    int32 max_network_level = 15;
    int64 magic_wallet_max_deposit = 16;
    int64 magic_wallet_max_credit = 17;
    repeated int64 feature_ids = 18;
}

message GetUserPackageStatusRequest
{
    int64 user_id = 1;
}

message GetUserPackageStatusResponse
{
    int64 user_id = 1;
    string package_purchase_method = 2;
    bool has_purchased_package = 3;
    bool is_club_member_active = 4;
    int64 wallet_balance = 5;
    int64 discount_balance = 6;
    bool can_activate_club_membership = 7;
    google.protobuf.StringValue last_order_number = 8;
    google.protobuf.Timestamp last_purchase_date = 9;
}

// ============= Customer Message Types =============

message GetCustomerPackagesRequest 
{
    bool include_inactive = 1;
    PackageTypeEnum package_type_filter = 2;
}

message GetCustomerPackagesResponse 
{
    repeated CustomerPackageModel models = 1;
}

message GetCustomerPackageDetailsRequest 
{
    int64 package_id = 1;
}

message GetCustomerPackageDetailsResponse 
{
    int64 id = 1;
    string title = 2;
    string description = 3;
    int64 price = 4;
    google.protobuf.StringValue image_path = 5;
    repeated PackageFeature features = 6;
    PurchaseRequirements requirements = 7;
}

message CustomerPurchasePackageRequest 
{
    int64 package_id = 1;
    PurchaseMethodEnum purchase_method = 2;
    string callback_url = 3;
}

message CustomerPurchasePackageResponse 
{
    bool success = 1;
    string message = 2;
    int64 order_id = 3;
    string payment_gateway_url = 4;
    string authority = 5;
}

message CustomerVerifyPackagePurchaseRequest 
{
    int64 order_id = 1;
    string authority = 2;
    string status = 3;
}

message CustomerVerifyPackagePurchaseResponse 
{
    bool success = 1;
    string message = 2;
    int64 transaction_id = 3;
    string reference_code = 4;
    PackagePurchaseInfo purchase_info = 5;
}

message GetCustomerPurchaseHistoryRequest 
{
    int64 user_id = 1;
    messages.PaginationState pagination_state = 2;
    PackageTypeEnum package_type_filter = 3;
    google.protobuf.Timestamp from_date = 4;
    google.protobuf.Timestamp to_date = 5;
}

message GetCustomerPurchaseHistoryResponse 
{
    messages.MetaData meta_data = 1;
    repeated PackagePurchaseHistory purchases = 2;
}

message CustomerPackageModel 
{
    int64 id = 1;
    string name = 2;
    string description = 3;
    int64 price = 4;
    string currency = 5;
    PackageTypeEnum package_type = 6;
    bool is_available = 7;
    string image_url = 8;
    int32 validity_days = 9;
    bool is_popular = 10;
    string short_description = 11;
    string title = 12;
    string image_path = 13;
    // New package-based fields
    int64 activation_fee = 14;
    double discount_multiplier = 15;
    double magic_wallet_multiplier = 16;
    int64 magic_wallet_max_deposit = 17;
    int64 magic_wallet_max_credit = 18;
    bool is_base_package = 19;
    bool supports_daya_purchase = 20;
    bool supports_direct_purchase = 21;
}

message PackageFeature 
{
    string title = 1;
    string description = 2;
    string icon = 3;
    bool is_highlighted = 4;
}

message PurchaseRequirements 
{
    bool requires_membership = 1;
    int64 minimum_wallet_balance = 2;
    repeated string restrictions = 3;
}

message PackagePurchaseInfo 
{
    int64 package_id = 1;
    string package_name = 2;
    int64 amount_paid = 3;
    google.protobuf.Timestamp purchase_date = 4;
    google.protobuf.Timestamp expiry_date = 5;
}

message PackagePurchaseHistory 
{
    int64 id = 1;
    int64 package_id = 2;
    string package_name = 3;
    int64 amount = 4;
    PackageTypeEnum package_type = 5;
    google.protobuf.Timestamp purchase_date = 6;
    google.protobuf.Timestamp expiry_date = 7;
    PaymentStatusEnum status = 8;
    string status_message = 9;
    string reference_code = 10;
}

enum PackageTypeEnum 
{
    PACKAGE_TYPE_BASIC = 0;
    PACKAGE_TYPE_GOLDEN = 1;
    PACKAGE_TYPE_PREMIUM = 2;
    PACKAGE_TYPE_SPECIAL = 3;
}

enum PurchaseMethodEnum 
{
    PURCHASE_METHOD_WALLET = 0;
    PURCHASE_METHOD_GATEWAY = 1;
    PURCHASE_METHOD_MIXED = 2;
}

enum PaymentStatusEnum 
{
    PAYMENT_STATUS_PENDING = 0;
    PAYMENT_STATUS_SUCCESS = 1;
    PAYMENT_STATUS_FAILED = 2;
    PAYMENT_STATUS_REFUNDED = 3;
}

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