forked from NdoleStudio/httpsms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbilling_usage.go
More file actions
30 lines (25 loc) · 1.21 KB
/
billing_usage.go
File metadata and controls
30 lines (25 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package entities
import (
"time"
"github.com/google/uuid"
)
// BillingUsage tracks the billing usage of an account
type BillingUsage struct {
ID uuid.UUID `json:"id" gorm:"primaryKey;type:uuid;" example:"32343a19-da5e-4b1b-a767-3298a73703cb"`
UserID UserID `json:"user_id" example:"WB7DRDWrJZRGbYrv2CKGkqbzvqdC"`
SentMessages uint `json:"sent_messages" example:"321"`
ReceivedMessages uint `json:"received_messages" example:"465"`
TotalCost uint `json:"total_cost" example:"0"`
StartTimestamp time.Time `json:"start_timestamp" example:"2022-01-01T00:00:00+00:00"`
EndTimestamp time.Time `json:"end_timestamp" example:"2022-01-31T23:59:59+00:00"`
CreatedAt time.Time `json:"created_at" example:"2022-06-05T14:26:02.302718+03:00"`
UpdatedAt time.Time `json:"updated_at" example:"2022-06-05T14:26:10.303278+03:00"`
}
// TotalMessages returns the sum of sent and received messages
func (usage *BillingUsage) TotalMessages() uint {
return usage.SentMessages + usage.ReceivedMessages
}
// IsEntitled checks if a user can send `count` messages
func (usage *BillingUsage) IsEntitled(count, limit uint) bool {
return (usage.TotalMessages() + count) < limit
}