<commit_before>package players

import (
	"errors"
	"github.com/imdario/mergo"
	"github.com/m4rw3r/uuid"
	"github.com/ckpt/backend-services/utils"
	"golang.org/x/crypto/bcrypt"
	"time"
	"os"
)

// We use dummy in memory storage for now
var storage PlayerStorage = NewRedisPlayerStorage()

// Init a message queue
var eventqueue utils.AMQPQueue = utils.NewRMQ(os.Getenv("CKPT_AMQP_URL"), "ckpt.events")

// Constants
type VoteType int

const (
	VOTE_FAV VoteType = iota
	VOTE_LOSER
)

// A Player is a player in CKPT, current or former.o// It also contains a User.
type Player struct {
	UUID    uuid.UUID `json:"uuid"`
	Profile Profile   `json:"profile"`
	Nick    string    `json:"nick"`
	User    User      `json:"user"`
	Active  bool      `json:"active"`
	// Quotes are just strings set by other players
	Quotes []string `json:"quotes"`
	// Gossip is one string from each
	// of the other players, indexed by uuid as string
	Gossip     map[string]string `json:"gossip"`
	Complaints []Complaint       `json:"complaints"`
	Votes      []Vote            `json:"votes"`
	// Debts where this player is the debitor
	Debts []Debt `json:"debts"`
}

// The basic profile of the player
type Profile struct {
	Name        string    `json:"name"`
	Picture     []byte    `json:"picture"`
	Birthday    time.Time `json:"birthday"`
	Email       string    `json:"email"`
	Description string    `json:"description"`
}

// A debt to another player (hte creditor)
type Debt struct {
	UUID        uuid.UUID `json:"uuid"`
	Debitor     uuid.UUID `json:"debitor"`
	Creditor    uuid.UUID `json:"creditor"`
	Description string    `json:"description"`
	Amount      int       `json:"amount"`
	Created     time.Time `json:"created"`
	Settled     time.Time `josn:"settled"`
}

// A complaint from another player
// for harassment or similar
type Complaint struct {
	From    *Player `json:"from"`
	Content string  `json:"content"`
}

type Vote struct {
	From *Player  `json:"from"`
	Type VoteType `json:"type"`
}

// A storage interface for Players
type PlayerStorage interface {
	Store(*Player) error
	Delete(uuid.UUID) error
	Load(uuid.UUID) (*Player, error)
	LoadAll() ([]*Player, error)
	LoadUser(username string) (*User, error)
}

//
// Player related functions and methods
//<commit_msg>Fix wrong json field name in debt struct.<commit_after>package players

import (
	"errors"
	"github.com/imdario/mergo"
	"github.com/m4rw3r/uuid"
	"github.com/ckpt/backend-services/utils"
	"golang.org/x/crypto/bcrypt"
	"time"
	"os"
)

// We use dummy in memory storage for now
var storage PlayerStorage = NewRedisPlayerStorage()

// Init a message queue
var eventqueue utils.AMQPQueue = utils.NewRMQ(os.Getenv("CKPT_AMQP_URL"), "ckpt.events")

// Constants
type VoteType int

const (
	VOTE_FAV VoteType = iota
	VOTE_LOSER
)

// A Player is a player in CKPT, current or former.o// It also contains a User.
type Player struct {
	UUID    uuid.UUID `json:"uuid"`
	Profile Profile   `json:"profile"`
	Nick    string    `json:"nick"`
	User    User      `json:"user"`
	Active  bool      `json:"active"`
	// Quotes are just strings set by other players
	Quotes []string `json:"quotes"`
	// Gossip is one string from each
	// of the other players, indexed by uuid as string
	Gossip     map[string]string `json:"gossip"`
	Complaints []Complaint       `json:"complaints"`
	Votes      []Vote            `json:"votes"`
	// Debts where this player is the debitor
	Debts []Debt `json:"debts"`
}

// The basic profile of the player
type Profile struct {
	Name        string    `json:"name"`
	Picture     []byte    `json:"picture"`
	Birthday    time.Time `json:"birthday"`
	Email       string    `json:"email"`
	Description string    `json:"description"`
}

// A debt to another player (hte creditor)
type Debt struct {
	UUID        uuid.UUID `json:"uuid"`
	Debitor     uuid.UUID `json:"debitor"`
	Creditor    uuid.UUID `json:"creditor"`
	Description string    `json:"description"`
	Amount      int       `json:"amount"`
	Created     time.Time `json:"created"`
	Settled     time.Time `json:"settled"`
}

// A complaint from another player
// for harassment or similar
type Complaint struct {
	From    *Player `json:"from"`
	Content string  `json:"content"`
}

type Vote struct {
	From *Player  `json:"from"`
	Type VoteType `json:"type"`
}

// A storage interface for Players
type PlayerStorage interface {
	Store(*Player) error
	Delete(uuid.UUID) error
	Load(uuid.UUID) (*Player, error)
	LoadAll() ([]*Player, error)
	LoadUser(username string) (*User, error)
}

//
// Player related functions and methods
//
{'fraction_non_alphanumeric': 0.12505494505494505, 'fraction_numerical': 0.0008791208791208791, 'mean_word_length': 3.466143277723258, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4581614', 'n_tokens_mistral': 1525, 'n_tokens_neox': 1488, 'n_words': 461}