1// SPDX-FileCopyrightText: Amolith <amolith@secluded.site>
2//
3// SPDX-License-Identifier: AGPL-3.0-or-later
4
5package lunatask
6
7import (
8 "errors"
9 "fmt"
10 "strings"
11)
12
13// Motivation represents why a task matters.
14type Motivation string
15
16// Valid motivation values.
17const (
18 // MotivationUnknown clears/unsets the motivation (default).
19 MotivationUnknown Motivation = "unknown"
20 MotivationMust Motivation = "must"
21 MotivationShould Motivation = "should"
22 MotivationWant Motivation = "want"
23)
24
25// Errors returned by Motivation operations.
26var (
27 // ErrInvalidMotivation is returned when parsing an unknown motivation string.
28 ErrInvalidMotivation = errors.New("invalid motivation")
29)
30
31// String returns the motivation value as a string.
32func (m Motivation) String() string {
33 return string(m)
34}
35
36// ParseMotivation parses a string to a Motivation value (case-insensitive).
37// Valid values: "unknown", "must", "should", "want".
38func ParseMotivation(str string) (Motivation, error) {
39 switch strings.ToLower(str) {
40 case "unknown":
41 return MotivationUnknown, nil
42 case "must":
43 return MotivationMust, nil
44 case "should":
45 return MotivationShould, nil
46 case "want":
47 return MotivationWant, nil
48 default:
49 return "", fmt.Errorf("%w: %q", ErrInvalidMotivation, str)
50 }
51}