2023-05-03 12:37:28 +00:00
|
|
|
package loyalty
|
2021-05-02 12:29:43 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2021-10-28 09:01:52 +00:00
|
|
|
ErrPAlreadyBet = errors.New("you already have a bet")
|
|
|
|
ErrPNoPrediction = errors.New("there's nothing to bet for")
|
|
|
|
ErrPBettingTimeOver = errors.New("betting time is over")
|
2021-05-02 12:29:43 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type PredictionBet struct {
|
|
|
|
Amount uint64
|
|
|
|
Team uint
|
|
|
|
}
|
|
|
|
|
|
|
|
type Prediction struct {
|
|
|
|
Active bool
|
|
|
|
Deadline time.Time
|
|
|
|
Bets map[string]PredictionBet
|
|
|
|
Teams []string
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewPrediction(teams []string, bettingTime time.Duration) *Prediction {
|
|
|
|
return &Prediction{
|
|
|
|
Active: false,
|
|
|
|
Deadline: time.Now().Add(bettingTime),
|
|
|
|
Bets: make(map[string]PredictionBet),
|
|
|
|
Teams: teams,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-25 13:58:35 +00:00
|
|
|
func (p *Prediction) AddBet(who string, teamID uint, amount uint64) error {
|
2021-05-02 12:29:43 +00:00
|
|
|
_, ok := p.Bets[who]
|
|
|
|
if ok {
|
|
|
|
return ErrPAlreadyBet
|
|
|
|
}
|
|
|
|
|
|
|
|
p.Bets[who] = PredictionBet{
|
|
|
|
Amount: amount,
|
2024-02-25 13:58:35 +00:00
|
|
|
Team: teamID,
|
2021-05-02 12:29:43 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|