veza/veza-backend-api/internal/models/royalty.go
2025-12-03 20:29:37 +01:00

143 lines
5.4 KiB
Go

package models
import (
"gorm.io/gorm"
"time"
"github.com/google/uuid"
)
// RoyaltyRecord enregistrement d'une royalty dans la base de données
type RoyaltyRecord struct {
ID uuid.UUID `json:"id" gorm:"type:uuid;primaryKey"`
ContentID uuid.UUID `json:"content_id" gorm:"type:uuid;not null;index"`
CreatorID uuid.UUID `json:"creator_id" gorm:"type:uuid;not null;index"`
Period string `json:"period" gorm:"not null;index"`
Plays int64 `json:"plays" gorm:"not null"`
Revenue float64 `json:"revenue" gorm:"not null"`
RoyaltyAmount float64 `json:"royalty_amount" gorm:"not null"`
RoyaltyRate float64 `json:"royalty_rate" gorm:"not null"`
Status string `json:"status" gorm:"not null;default:'calculated'"`
CalculatedAt time.Time `json:"calculated_at" gorm:"not null"`
PaidAt *time.Time `json:"paid_at,omitempty"`
CreatedAt time.Time `json:"created_at" gorm:"autoCreateTime"`
UpdatedAt time.Time `json:"updated_at" gorm:"autoUpdateTime"`
}
// RoyaltyPayout paiement de royalties dans la base de données
type RoyaltyPayout struct {
ID uuid.UUID `json:"id" gorm:"type:uuid;primaryKey"`
PayoutID string `json:"payout_id" gorm:"uniqueIndex;not null"`
CreatorID uuid.UUID `json:"creator_id" gorm:"type:uuid;not null;index"`
Amount float64 `json:"amount" gorm:"not null"`
Currency string `json:"currency" gorm:"not null;default:'EUR'"`
Period string `json:"period" gorm:"not null;index"`
Status string `json:"status" gorm:"not null;default:'pending'"`
PaymentMethod string `json:"payment_method" gorm:"not null"`
TransactionID string `json:"transaction_id,omitempty"`
ProcessedAt time.Time `json:"processed_at" gorm:"not null"`
EstimatedArrival time.Time `json:"estimated_arrival" gorm:"not null"`
Notes string `json:"notes,omitempty"`
CreatedAt time.Time `json:"created_at" gorm:"autoCreateTime"`
UpdatedAt time.Time `json:"updated_at" gorm:"autoUpdateTime"`
}
// RoyaltyRate taux de royalty par type de contenu
type RoyaltyRate struct {
ID uuid.UUID `json:"id" gorm:"type:uuid;primaryKey"`
ContentType string `json:"content_type" gorm:"uniqueIndex;not null"`
Rate float64 `json:"rate" gorm:"not null"`
Description string `json:"description,omitempty"`
IsActive bool `json:"is_active" gorm:"not null;default:true"`
CreatedAt time.Time `json:"created_at" gorm:"autoCreateTime"`
UpdatedAt time.Time `json:"updated_at" gorm:"autoUpdateTime"`
}
// CreatorRoyaltyRate taux de royalty personnalisé par créateur
type CreatorRoyaltyRate struct {
ID uuid.UUID `json:"id" gorm:"type:uuid;primaryKey"`
CreatorID uuid.UUID `json:"creator_id" gorm:"type:uuid;not null;uniqueIndex"`
Rate float64 `json:"rate" gorm:"not null"`
Reason string `json:"reason,omitempty"`
IsActive bool `json:"is_active" gorm:"not null;default:true"`
CreatedAt time.Time `json:"created_at" gorm:"autoCreateTime"`
UpdatedAt time.Time `json:"updated_at" gorm:"autoUpdateTime"`
}
// RoyaltyConfig configuration des royalties
type RoyaltyConfig struct {
ID uuid.UUID `json:"id" gorm:"type:uuid;primaryKey"`
PlatformFeeRate float64 `json:"platform_fee_rate" gorm:"not null;default:0.15"`
MinimumPayoutAmount float64 `json:"minimum_payout_amount" gorm:"not null;default:50.0"`
PayoutSchedule string `json:"payout_schedule" gorm:"not null;default:'monthly'"`
ProcessingDelay int `json:"processing_delay" gorm:"not null;default:3"`
Currency string `json:"currency" gorm:"not null;default:'EUR'"`
IsActive bool `json:"is_active" gorm:"not null;default:true"`
CreatedAt time.Time `json:"created_at" gorm:"autoCreateTime"`
UpdatedAt time.Time `json:"updated_at" gorm:"autoUpdateTime"`
}
// TableName spécifie le nom de la table pour RoyaltyRecord
func (RoyaltyRecord) TableName() string {
return "royalty_records"
}
// TableName spécifie le nom de la table pour RoyaltyPayout
func (RoyaltyPayout) TableName() string {
return "royalty_payouts"
}
// TableName spécifie le nom de la table pour RoyaltyRate
func (RoyaltyRate) TableName() string {
return "royalty_rates"
}
// TableName spécifie le nom de la table pour CreatorRoyaltyRate
func (CreatorRoyaltyRate) TableName() string {
return "creator_royalty_rates"
}
// TableName spécifie le nom de la table pour RoyaltyConfig
func (RoyaltyConfig) TableName() string {
return "royalty_config"
}
// BeforeCreate hook GORM pour générer UUID si non défini
func (m *RoyaltyRecord) BeforeCreate(tx *gorm.DB) error {
if m.ID == uuid.Nil {
m.ID = uuid.New()
}
return nil
}
// BeforeCreate hook GORM pour générer UUID si non défini
func (m *RoyaltyPayout) BeforeCreate(tx *gorm.DB) error {
if m.ID == uuid.Nil {
m.ID = uuid.New()
}
return nil
}
// BeforeCreate hook GORM pour générer UUID si non défini
func (m *RoyaltyRate) BeforeCreate(tx *gorm.DB) error {
if m.ID == uuid.Nil {
m.ID = uuid.New()
}
return nil
}
// BeforeCreate hook GORM pour générer UUID si non défini
func (m *CreatorRoyaltyRate) BeforeCreate(tx *gorm.DB) error {
if m.ID == uuid.Nil {
m.ID = uuid.New()
}
return nil
}
// BeforeCreate hook GORM pour générer UUID si non défini
func (m *RoyaltyConfig) BeforeCreate(tx *gorm.DB) error {
if m.ID == uuid.Nil {
m.ID = uuid.New()
}
return nil
}