1+ syntax = "proto3" ;
2+
3+ package discount ;
4+
5+ service Discount {
6+ // Admin APIs
7+ rpc CreateVoucher (CreateVoucherRequest ) returns (CreateVoucherResponse ); // Creates a new discount voucher
8+ rpc DeleteVoucher (DeleteVoucherRequest ) returns (DeleteVoucherResponse ); // Deletes a voucher by code
9+ rpc UpdateVoucherRestrictions (UpdateVoucherRestrictionsRequest ) returns (UpdateVoucherRestrictionsResponse ); // Updates restrictions on a voucher
10+ rpc GetVouchers (GetVouchersRequest ) returns (GetVouchersResponse ); // Retrieves a list of vouchers with filters and pagination
11+
12+ // User APIs
13+ rpc ValidateVoucher (ValidateVoucherRequest ) returns (ValidateVoucherResponse ); // Validates if a voucher is applicable
14+ rpc ApplyVoucher (ApplyVoucherRequest ) returns (ApplyVoucherResponse ); // Applies a voucher to a purchase
15+ }
16+
17+ enum DiscountType {
18+ FIXED = 0 ; // Fixed amount discount
19+ PERCENTAGE = 1 ; // Percentage-based discount
20+ }
21+
22+ message Voucher {
23+ string code = 1 ; // Unique voucher code
24+ DiscountType discount_type = 2 ; // Type of discount
25+ double discount_value = 3 ; // Value of the discount
26+ bool is_active = 4 ; // Indicates if the voucher is active
27+ int32 usage_count = 5 ; // Number of times the voucher has been used
28+ optional Restrictions restrictions = 6 ; // Optional restrictions applied to the voucher
29+ }
30+
31+ message Restrictions {
32+ optional bool new_users_only = 1 ; // Restricts voucher to new users
33+ optional int32 max_uses_per_user = 2 ; // Maximum times a user can use this voucher
34+ optional double min_purchase_requirement = 3 ; // Minimum amount required to use the voucher
35+ optional double max_discount_cap = 4 ; // Max discount amount for percentage-based vouchers
36+ repeated string applicable_services = 5 ; // List of services/plans the voucher applies to
37+ optional bool has_applicable_services = 9 ;
38+ optional string start_date = 6 ; // Start date of voucher validity (ISO 8601 format)
39+ optional string expire_date = 7 ; // Expiry date of voucher validity (ISO 8601 format)
40+ optional int32 global_usage_limit = 8 ; // Maximum total usage count across all users
41+ }
42+
43+ // Admin Requests
44+ message CreateVoucherRequest {
45+ string code = 1 ; // Unique voucher code
46+ DiscountType discount_type = 2 ; // Type of discount
47+ double discount_value = 3 ; // Value of the discount
48+ optional Restrictions restrictions = 4 ;
49+ }
50+
51+ message CreateVoucherResponse {
52+ Voucher voucher = 1 ; // Response message confirming voucher creation
53+ }
54+
55+ message DeleteVoucherRequest {
56+ string code = 1 ; // Voucher code to be deleted
57+ }
58+ message DeleteVoucherResponse {
59+ bool success = 1 ; // Response message confirming deletion
60+ }
61+
62+ message UpdateVoucherRestrictionsRequest {
63+ string code = 1 ; // Voucher code to update restrictions
64+ optional bool is_active = 2 ;
65+ Restrictions restrictions = 3 ; // New restrictions for the voucher
66+ }
67+ message UpdateVoucherRestrictionsResponse {
68+ Voucher voucher = 1 ; // Response message confirming update
69+ }
70+
71+ message GetVouchersRequest {
72+ optional DiscountType discount_type = 1 ; // Filter by discount type
73+ optional bool is_active = 2 ; // Filter by active status
74+ optional string service_name = 3 ; // Filter by applicable service
75+ optional int32 page_number = 4 ; // Pagination: page number
76+ optional int32 page_size = 5 ; // Pagination: number of items per page
77+ }
78+
79+ message GetVouchersResponse {
80+ repeated Voucher vouchers = 1 ; // List of vouchers
81+ int32 total_count = 2 ; // Total number of vouchers matching the filters
82+ }
83+
84+ // User Requests
85+ message ValidateVoucherRequest {
86+ string code = 1 ; // Voucher code to validate
87+ string user_id = 2 ; // ID of the user trying to use the voucher
88+ double purchase_amount = 3 ; // Amount of the purchase
89+ string service_name = 4 ; // Service name where the voucher is applied
90+ }
91+
92+ message ValidateVoucherResponse {
93+ bool is_valid = 1 ; // Indicates if the voucher is valid for the given purchase
94+ bool success = 2 ; // Validation message
95+ double discount_amount = 3 ; // Discount amount applicable
96+ double final_price = 4 ; // Final price after applying the discount
97+ }
98+
99+ message ApplyVoucherRequest {
100+ string code = 1 ; // Voucher code to apply
101+ string user_id = 2 ; // ID of the user using the voucher
102+ double purchase_amount = 3 ; // Amount of the purchase before discount
103+ string service_name = 4 ; // Service name where the voucher is applied
104+ }
105+
106+ message ApplyVoucherResponse {
107+ bool success = 1 ; // Indicates if voucher application was successful
108+ double discount_amount = 2 ; // Discount amount applicable
109+ double final_price = 3 ; // Final price after applying the discount
110+ }
0 commit comments