syntax = "proto3";

package manualpayment;

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

service ManualPaymentContract
{
    rpc CreateManualPayment(CreateManualPaymentRequest) returns (CreateManualPaymentResponse){
        option (google.api.http) = {
            post: "/CreateManualPayment"
            body: "*"
        };
    };

    rpc ApproveManualPayment(ApproveManualPaymentRequest) returns (google.protobuf.Empty){
        option (google.api.http) = {
            post: "/ApproveManualPayment"
            body: "*"
        };
    };

    rpc RejectManualPayment(RejectManualPaymentRequest) returns (google.protobuf.Empty){
        option (google.api.http) = {
            post: "/RejectManualPayment"
            body: "*"
        };
    };

    rpc GetAllManualPayments(GetAllManualPaymentsRequest) returns (GetAllManualPaymentsResponse){
        option (google.api.http) = {
            get: "/GetAllManualPayments"
        };
    };

    rpc ProcessManualMembershipPayment(ProcessManualMembershipPaymentRequest) returns (ProcessManualMembershipPaymentResponse){
        option (google.api.http) = {
            post: "/ProcessManualMembershipPayment"
            body: "*"
        };
    };
}

// Enums mirroring CMSMicroservice.Domain.Enums.ManualPaymentType
enum ManualPaymentType
{
    ManualPaymentType_Unknown = 0;
    ManualPaymentType_CashDeposit = 1;
    ManualPaymentType_DiscountWalletCharge = 2;
    ManualPaymentType_NetworkWalletCharge = 3;
    ManualPaymentType_Settlement = 4;
    ManualPaymentType_ErrorCorrection = 5;
    ManualPaymentType_Refund = 6;
    ManualPaymentType_Other = 99;
}

// Enums mirroring CMSMicroservice.Domain.Enums.ManualPaymentStatus
enum ManualPaymentStatus
{
    ManualPaymentStatus_Pending = 0;
    ManualPaymentStatus_Approved = 1;
    ManualPaymentStatus_Rejected = 2;
    ManualPaymentStatus_Cancelled = 3;
}

message CreateManualPaymentRequest
{
    int64 user_id = 1;
    int64 amount = 2;           // [DEPRECATED] مبلغ از پکیج خوانده می‌شود — نادیده گرفته می‌شود
    ManualPaymentType type = 3;
    string description = 4;
    google.protobuf.StringValue reference_number = 5;
    google.protobuf.StringValue image_path = 6;
    google.protobuf.Int64Value image_document_id = 7;
    FileUploadModel image_file = 8;
    int64 package_id = 9;       // شناسه پکیج — اگر 0 باشد، پکیج پایه استفاده می‌شود
}

message CreateManualPaymentResponse
{
    int64 id = 1;
}

message ApproveManualPaymentRequest
{
    int64 manual_payment_id = 1;
    google.protobuf.StringValue approval_note = 2;
}

message RejectManualPaymentRequest
{
    int64 manual_payment_id = 1;
    string rejection_reason = 2;
}

message GetAllManualPaymentsRequest
{
    int32 page_number = 1;
    int32 page_size = 2;
    google.protobuf.Int64Value user_id = 3;
    google.protobuf.Int32Value status = 4;
    google.protobuf.Int32Value type = 5;
    google.protobuf.Int64Value requested_by = 6;
    google.protobuf.BoolValue order_by_descending = 7;
}

message GetAllManualPaymentsResponse
{
    messages.MetaData meta_data = 1;
    repeated ManualPaymentModel models = 2;
}

message ManualPaymentModel
{
    int64 id = 1;
    int64 user_id = 2;
    string user_full_name = 3;
    string user_mobile = 4;
    int64 amount = 5;
    ManualPaymentType type = 6;
    string type_display = 7;
    string description = 8;
    google.protobuf.StringValue reference_number = 9;
    ManualPaymentStatus status = 10;
    string status_display = 11;
    int64 requested_by = 12;
    string requested_by_name = 13;
    google.protobuf.Int64Value approved_by = 14;
    google.protobuf.StringValue approved_by_name = 15;
    google.protobuf.Timestamp approved_at = 16;
    google.protobuf.StringValue rejection_reason = 17;
    google.protobuf.Int64Value transaction_id = 18;
    google.protobuf.Timestamp created = 19;
    google.protobuf.StringValue image_path = 20;
    google.protobuf.Int64Value image_document_id = 21;
    google.protobuf.StringValue package_name = 22; // نام پکیج کاربر
}

message ProcessManualMembershipPaymentRequest
{
    int64 user_id = 1;
    int64 amount = 2;
    string reference_number = 3;
    google.protobuf.StringValue description = 4;
}

message ProcessManualMembershipPaymentResponse
{
    int64 transaction_id = 1;
    int64 order_id = 2;
    int64 new_wallet_balance = 3;
    string message = 4;
}

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

