1
0
Fork 0
mirror of https://git.sr.ht/~ashkeel/strimertul synced 2024-09-18 01:50:50 +00:00
strimertul/loyalty/prediction.go

47 lines
858 B
Go
Raw Normal View History

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,
}
}
func (p *Prediction) AddBet(who string, teamId uint, amount uint64) error {
_, ok := p.Bets[who]
if ok {
return ErrPAlreadyBet
}
p.Bets[who] = PredictionBet{
Amount: amount,
Team: teamId,
}
return nil
}