summaryrefslogtreecommitdiff
path: root/types.go
blob: eb459c9f2679c25d73e88981ebd0a0e5add0553d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package main

import "fmt"

type Gender int32

const (
	GenderM Gender = iota
	GenderF
)

var GenderStrings = []string{"Herren", "Damen"}
var GenderStringsShort = []string{"H", "D"}

func (g Gender) String() string {
	return GenderStrings[g]
}

func (g Gender) ShortString() string {
	return GenderStringsShort[g]
}

func (g Gender) Engarde() (string, error) {
	switch g {
	case GenderM:
		return "masculin", nil
	case GenderF:
		return "feminin", nil
	default:
		return "", fmt.Errorf("unknown gender value '%d'", g)
	}
}

func GenderFromString(content string) (Gender, error) {
	switch content {
	case "M":
		return GenderM, nil
	case "F":
		return GenderF, nil
	default:
		return 0, fmt.Errorf("unknown gender value '%s'", content)
	}
}

func (g *Gender) UnmarshalCSV(content []byte) error {
	if res, err := GenderFromString(string(content)); err == nil {
		*g = res
		return nil
	} else {
		return err
	}
}

type AgeGroup int32

const (
	AgeSenior AgeGroup = iota
	AgeVeteran
)

var AgeGroupStrings = []string{"Senioren", "Veteranen"}

func (a AgeGroup) String() string {
	return AgeGroupStrings[a]
}

func (a AgeGroup) Engarde() (string, error) {
	switch a {
	case AgeVeteran:
		return "veteran", nil
	case AgeSenior:
		return "senior", nil
	default:
		return "", fmt.Errorf("unknown age group value '%d'", a)
	}
}

func AgeGroupFromString(content string) (AgeGroup, error) {
	switch content {
	case "V":
		return AgeVeteran, nil
	case "S":
		return AgeSenior, nil
	default:
		return 0, fmt.Errorf("unknown age group value '%s'", content)
	}
}

type Weapon int32

const (
	Epee Weapon = iota
	Foil
	Sabre
)

var WeaponStrings = []string{"Degen", "Florett", "Säbel"}
var WeaponShorts = []string{"D", "F", "S"}

func (w Weapon) String() string {
	return WeaponStrings[w]
}

func (w Weapon) ShortString() string {
	return WeaponShorts[w]
}

func (w Weapon) Engarde() (string, error) {
	switch w {
	case Epee:
		return "epee", nil
	case Foil:
		return "fleuret", nil
	case Sabre:
		return "sabre", nil
	default:
		return "", fmt.Errorf("unknown weapon value '%d'", w)
	}
}

func WeaponFromString(content string) (Weapon, error) {
	switch content {
	case "D":
		return Epee, nil
	case "S":
		return Sabre, nil
	case "F":
		return Foil, nil
	default:
		return 0, fmt.Errorf("unknown weapon value '%s'", content)
	}
}