package domain import "net/url" type BaseTribe struct { id int name string tag string numMembers int numVillages int points int allPoints int rank int od OpponentsDefeated profileURL *url.URL } const baseTribeModelName = "BaseTribe" //nolint:gocyclo func NewBaseTribe( id int, name string, tag string, numMembers int, numVillages int, points int, allPoints int, rank int, od OpponentsDefeated, profileURL *url.URL, ) (BaseTribe, error) { if id < 1 { return BaseTribe{}, ValidationError{ Model: baseTribeModelName, Field: "id", Err: MinGreaterEqualError{ Min: 1, Current: id, }, } } if l := len(name); l < tribeNameMinLength || l > tribeNameMaxLength { return BaseTribe{}, ValidationError{ Model: baseTribeModelName, Field: "name", Err: LenOutOfRangeError{ Min: tribeNameMinLength, Max: tribeNameMaxLength, Current: l, }, } } // we convert tag to []rune to get the correct length // e.g. for tags such as Орловы, which takes 12 bytes rather than 6 // explanation: https://golangbyexample.com/number-characters-string-golang/ if l := len([]rune(tag)); l < tribeTagMinLength || l > tribeTagMaxLength { return BaseTribe{}, ValidationError{ Model: baseTribeModelName, Field: "tag", Err: LenOutOfRangeError{ Min: tribeTagMinLength, Max: tribeTagMaxLength, Current: l, }, } } if numMembers < 0 { return BaseTribe{}, ValidationError{ Model: baseTribeModelName, Field: "numMembers", Err: MinGreaterEqualError{ Min: 0, Current: numMembers, }, } } if numVillages < 0 { return BaseTribe{}, ValidationError{ Model: baseTribeModelName, Field: "numVillages", Err: MinGreaterEqualError{ Min: 0, Current: numVillages, }, } } if points < 0 { return BaseTribe{}, ValidationError{ Model: baseTribeModelName, Field: "points", Err: MinGreaterEqualError{ Min: 0, Current: points, }, } } if allPoints < 0 { return BaseTribe{}, ValidationError{ Model: baseTribeModelName, Field: "allPoints", Err: MinGreaterEqualError{ Min: 0, Current: allPoints, }, } } if rank < 0 { return BaseTribe{}, ValidationError{ Model: baseTribeModelName, Field: "rank", Err: MinGreaterEqualError{ Min: 0, Current: rank, }, } } if profileURL == nil { return BaseTribe{}, ValidationError{ Model: baseTribeModelName, Field: "profileURL", Err: ErrNotNil, } } return BaseTribe{ id: id, name: name, tag: tag, numMembers: numMembers, numVillages: numVillages, points: points, allPoints: allPoints, rank: rank, od: od, profileURL: profileURL, }, nil } func (b BaseTribe) ID() int { return b.id } func (b BaseTribe) Name() string { return b.name } func (b BaseTribe) Tag() string { return b.tag } func (b BaseTribe) NumMembers() int { return b.numMembers } func (b BaseTribe) NumVillages() int { return b.numVillages } func (b BaseTribe) Points() int { return b.points } func (b BaseTribe) AllPoints() int { return b.allPoints } func (b BaseTribe) Rank() int { return b.rank } func (b BaseTribe) OD() OpponentsDefeated { return b.od } func (b BaseTribe) ProfileURL() *url.URL { return b.profileURL } type BaseTribes []BaseTribe