syntax = "proto3";

package userwallet;

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

service UserWalletContract
{
    rpc CreateNewUserWallet(CreateNewUserWalletRequest) returns (CreateNewUserWalletResponse){
        option (google.api.http) = {
            post: "/CreateNewUserWallet"
            body: "*"
        };
    };
    rpc UpdateUserWallet(UpdateUserWalletRequest) returns (google.protobuf.Empty){
        option (google.api.http) = {
            put: "/UpdateUserWallet"
            body: "*"
        };
    };
    rpc DeleteUserWallet(DeleteUserWalletRequest) returns (google.protobuf.Empty){
        option (google.api.http) = {
            delete: "/DeleteUserWallet"
            body: "*"
        };
    };
    rpc GetUserWallet(GetUserWalletRequest) returns (GetUserWalletResponse){
        option (google.api.http) = {
            get: "/GetUserWallet"
            
        };
    };
    rpc GetAllUserWalletByFilter(GetAllUserWalletByFilterRequest) returns (GetAllUserWalletByFilterResponse){
        option (google.api.http) = {
            get: "/GetAllUserWalletByFilter"
            
        };
    };
    
    // ============= Customer-specific Methods =============
    
    rpc GetCustomerWallet(google.protobuf.Empty) returns (GetCustomerWalletResponse){
        option (google.api.http) = {
            get: "/Customer/GetWallet"
        };
    };
    rpc GetCustomerWalletHistory(GetCustomerWalletHistoryRequest) returns (GetCustomerWalletHistoryResponse){
        option (google.api.http) = {
            post: "/Customer/GetWalletHistory"
            body: "*"
        };
    };
    rpc CustomerWithdrawBalance(CustomerWithdrawBalanceRequest) returns (google.protobuf.Empty){
        option (google.api.http) = {
            post: "/Customer/WithdrawBalance"
            body: "*"
        };
    };
    rpc GetCustomerWithdrawals(GetCustomerWithdrawalsRequest) returns (GetCustomerWithdrawalsResponse){
        option (google.api.http) = {
            post: "/Customer/GetWithdrawals"
            body: "*"
        };
    };
    rpc GetCustomerWithdrawalSettings(google.protobuf.Empty) returns (GetCustomerWithdrawalSettingsResponse){
        option (google.api.http) = {
            get: "/Customer/GetWithdrawalSettings"
        };
    };

    // ============= Magic Wallet Methods =============

    rpc InitiateMagicCharge(InitiateMagicChargeRequest) returns (InitiateMagicChargeResponse){
        option (google.api.http) = {
            post: "/Customer/InitiateMagicCharge"
            body: "*"
        };
    };
    rpc GetMagicWalletStatus(google.protobuf.Empty) returns (GetMagicWalletStatusResponse){
        option (google.api.http) = {
            get: "/Customer/GetMagicWalletStatus"
        };
    };

    rpc VerifyMagicCharge(VerifyWalletChargeRequest) returns (VerifyWalletChargeResponse){
        option (google.api.http) = {
            post: "/Customer/VerifyMagicCharge"
            body: "*"
        };
    };

    // ============= Discount Wallet Methods =============

    rpc InitiateDiscountCharge(InitiateDiscountChargeRequest) returns (InitiateDiscountChargeResponse){
        option (google.api.http) = {
            post: "/Customer/InitiateDiscountCharge"
            body: "*"
        };
    };
    rpc VerifyDiscountCharge(VerifyWalletChargeRequest) returns (VerifyWalletChargeResponse){
        option (google.api.http) = {
            post: "/Customer/VerifyDiscountCharge"
            body: "*"
        };
    };

    // ============= Credit (Main) Wallet Methods =============

    rpc InitiateCreditCharge(InitiateCreditChargeRequest) returns (InitiateCreditChargeResponse){
        option (google.api.http) = {
            post: "/Customer/InitiateCreditCharge"
            body: "*"
        };
    };
    rpc VerifyCreditCharge(VerifyWalletChargeRequest) returns (VerifyWalletChargeResponse){
        option (google.api.http) = {
            post: "/Customer/VerifyCreditCharge"
            body: "*"
        };
    };

    // ============= Admin Manual Credit Charge =============

    rpc AdminManualCreditCharge(AdminManualCreditChargeRequest) returns (AdminManualCreditChargeResponse){
        option (google.api.http) = {
            post: "/Admin/ManualCreditCharge"
            body: "*"
        };
    };
    rpc GetManualCreditCharges(GetManualCreditChargesRequest) returns (GetManualCreditChargesResponse){
        option (google.api.http) = {
            get: "/Admin/GetManualCreditCharges"
        };
    };
}
message CreateNewUserWalletRequest
{
    int64 user_id = 1;
    int64 balance = 2;
    int64 network_balance = 3;
}
message CreateNewUserWalletResponse
{
    int64 id = 1;
}
message UpdateUserWalletRequest
{
    int64 id = 1;
    int64 user_id = 2;
    int64 balance = 3;
    int64 network_balance = 4;
}
message DeleteUserWalletRequest
{
    int64 id = 1;
}
message GetUserWalletRequest
{
    int64 id = 1;
}
message GetUserWalletResponse
{
    int64 id = 1;
    int64 user_id = 2;
    int64 balance = 3;
    int64 network_balance = 4;
}
message GetAllUserWalletByFilterRequest
{
    messages.PaginationState pagination_state = 1;
    google.protobuf.StringValue sort_by = 2;
    GetAllUserWalletByFilterFilter filter = 3;
}
message GetAllUserWalletByFilterFilter
{
    google.protobuf.Int64Value id = 1;
    google.protobuf.Int64Value user_id = 2;
    google.protobuf.Int64Value balance = 3;
    google.protobuf.Int64Value network_balance = 4;
}
message GetAllUserWalletByFilterResponse
{
    messages.MetaData meta_data = 1;
    repeated GetAllUserWalletByFilterResponseModel models = 2;
}
message GetAllUserWalletByFilterResponseModel
{
    int64 id = 1;
    int64 user_id = 2;
    int64 balance = 3;
    int64 network_balance = 4;
    string user_name = 5;
    int64 discount_balance = 6;
}

// ============= Customer-specific Messages =============

message GetCustomerWalletResponse
{
    int64 balance = 1;
    int64 network_balance = 2;
    int64 discount_balance = 3;
    int32 wallet_mode = 4; // 0=Normal, 1=Magic
}

message GetCustomerWalletHistoryRequest
{
    google.protobuf.Int64Value reference_id = 1;
    google.protobuf.BoolValue is_increase = 2;
}

message GetCustomerWalletHistoryResponse
{
    messages.MetaData meta_data = 1;
    repeated CustomerWalletHistoryModel models = 2;
}

message CustomerWalletHistoryModel
{
    int64 current_balance = 1;
    int64 change_value = 2;
    int64 current_network_balance = 3;
    int64 change_nerwork_value = 4;
    int64 current_discount_balance = 5;
    int64 change_discount_value = 6;
    bool is_increase = 7;
    google.protobuf.Int64Value refrence_id = 8;
    google.protobuf.Timestamp created_at = 9;
}

message CustomerWithdrawBalanceRequest
{
    int64 payout_id = 1;
    int32 withdrawal_method = 2; // 0: Cash, 1: Diamond
    google.protobuf.StringValue iban_number = 3;
}

message GetCustomerWithdrawalsRequest
{
    google.protobuf.Int32Value status = 1;
}

message GetCustomerWithdrawalsResponse
{
    messages.MetaData meta_data = 1;
    repeated CustomerWithdrawalModel models = 2;
}

message CustomerWithdrawalModel
{
    int64 id = 1;
    int64 week_definition_id = 2;
    string week_display_name = 3;
    int64 total_amount = 4;
    int32 status = 5;
    google.protobuf.Int32Value withdrawal_method = 6;
    string iban_number = 7;
    google.protobuf.Timestamp created = 8;
}

message GetCustomerWithdrawalSettingsResponse
{
    int64 min_withdrawal_amount = 1;
}

// ============= Magic Wallet Messages =============

message InitiateMagicChargeRequest
{
    int64 amount = 1; // مبلغ واریزی (تومان)
}

message InitiateMagicChargeResponse
{
    bool is_success = 1;
    string gateway_url = 2;
    string error_message = 3;
}

message GetMagicWalletStatusResponse
{
    int32 wallet_mode = 1; // 0=Normal, 1=Magic
    int64 magic_total_deposited = 2;
    int64 magic_total_credited = 3;
    int64 magic_max_deposit = 4;
    int64 magic_remaining_deposit = 5;
    int64 balance = 6;
    google.protobuf.Timestamp magic_activated_at = 7;
    int32 purchase_cycle_count = 8; // تعداد دورهای خرید پکیج (0 = هنوز هیچ دوری تکمیل نشده)
    double magic_multiplier = 9; // ضریب جادویی (مثلاً 2.5)
    int64 magic_max_credit = 10; // حداکثر اعتبار (ریال)
}

// ============= Discount Wallet Messages =============

message InitiateDiscountChargeRequest
{
    int64 amount = 1; // مبلغ واریزی (تومان)
}

message InitiateDiscountChargeResponse
{
    bool is_success = 1;
    string gateway_url = 2;
    string error_message = 3;
}

// ============= Credit (Main) Wallet Messages =============

message InitiateCreditChargeRequest
{
    int64 amount = 1; // مبلغ واریزی (تومان)
}

message InitiateCreditChargeResponse
{
    bool is_success = 1;
    string gateway_url = 2;
    string error_message = 3;
}

// ============= Wallet Verify Messages =============

message VerifyWalletChargeRequest
{
    string authority = 1;
    string status = 2;
}

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

// ============= Admin Manual Credit Charge Messages =============

message AdminManualCreditChargeRequest
{
    int64 user_id = 1;
    int64 amount = 2; // تومان
    google.protobuf.StringValue note = 3;
}

message AdminManualCreditChargeResponse
{
    bool success = 1;
    string message = 2;
    int64 transaction_id = 3;
    int64 new_balance = 4;
}

message GetManualCreditChargesRequest
{
    messages.PaginationState pagination_state = 1;
    google.protobuf.StringValue sort_by = 2;
    GetManualCreditChargesFilter filter = 3;
}

message GetManualCreditChargesFilter
{
    google.protobuf.Int64Value user_id = 1;
    google.protobuf.Int64Value transaction_id = 2;
    google.protobuf.StringValue ref_id = 3;
    google.protobuf.Timestamp created_from = 4;
    google.protobuf.Timestamp created_to = 5;
}

message GetManualCreditChargesResponse
{
    messages.MetaData meta_data = 1;
    repeated ManualCreditChargeModel models = 2;
}

message ManualCreditChargeModel
{
    int64 transaction_id = 1;
    int64 user_id = 2;
    string user_name = 3;
    int64 amount = 4;
    string description = 5;
    string ref_id = 6;
    int64 new_balance = 7;
    google.protobuf.Timestamp created = 8;
    google.protobuf.Timestamp payment_date = 9;
}