summaryrefslogtreecommitdiff
path: root/internal/cardtype.go
blob: 9b49236914dcf23283c396edf30103b463c0633a (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
package internal

import (
	"os"
	"path/filepath"
	"strings"
)

// CardType represents the type of flashcard
type CardType string

const (
	// CardTypeEnBg represents English-Bulgarian cards (default)
	CardTypeEnBg CardType = "en-bg"
	// CardTypeBgBg represents Bulgarian-Bulgarian cards
	CardTypeBgBg CardType = "bg-bg"
)

// String returns the string representation of the card type
func (ct CardType) String() string {
	return string(ct)
}

// IsBgBg returns true if this is a Bulgarian-Bulgarian card
func (ct CardType) IsBgBg() bool {
	return ct == CardTypeBgBg
}

// DisplayName returns a human-readable name for the card type
func (ct CardType) DisplayName() string {
	switch ct {
	case CardTypeBgBg:
		return "Bulgarian → Bulgarian"
	default:
		return "English → Bulgarian"
	}
}

// SaveCardType saves the card type to a file in the card directory
func SaveCardType(cardDir string, cardType CardType) error {
	cardTypePath := filepath.Join(cardDir, "cardtype.txt")
	return os.WriteFile(cardTypePath, []byte(string(cardType)), 0644)
}

// LoadCardType loads the card type from a card directory
// Returns CardTypeEnBg as default for backwards compatibility
func LoadCardType(cardDir string) CardType {
	cardTypePath := filepath.Join(cardDir, "cardtype.txt")
	data, err := os.ReadFile(cardTypePath)
	if err != nil {
		return CardTypeEnBg
	}
	cardType := CardType(strings.TrimSpace(string(data)))
	if cardType == CardTypeBgBg {
		return CardTypeBgBg
	}
	return CardTypeEnBg
}