File: label_types.go

package info (click to toggle)
golang-github-henrybear327-go-proton-api 1.0.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,088 kB
  • sloc: sh: 55; makefile: 26
file content (90 lines) | stat: -rw-r--r-- 1,319 bytes parent folder | download
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
package proton

import (
	"encoding/json"
	"strings"
)

const (
	InboxLabel        = "0"
	AllDraftsLabel    = "1"
	AllSentLabel      = "2"
	TrashLabel        = "3"
	SpamLabel         = "4"
	AllMailLabel      = "5"
	ArchiveLabel      = "6"
	SentLabel         = "7"
	DraftsLabel       = "8"
	OutboxLabel       = "9"
	StarredLabel      = "10"
	AllScheduledLabel = "12"
)

type Label struct {
	ID       string
	ParentID string

	Name  string
	Path  []string
	Color string
	Type  LabelType
}

func (label *Label) UnmarshalJSON(data []byte) error {
	type Alias Label

	aux := &struct {
		Path string

		*Alias
	}{
		Alias: (*Alias)(label),
	}

	if err := json.Unmarshal(data, &aux); err != nil {
		return err
	}

	label.Path = strings.Split(aux.Path, "/")

	return nil
}

func (label Label) MarshalJSON() ([]byte, error) {
	type Alias Label

	aux := &struct {
		Path string

		*Alias
	}{
		Path:  strings.Join(label.Path, "/"),
		Alias: (*Alias)(&label),
	}

	return json.Marshal(aux)
}

type CreateLabelReq struct {
	Name  string
	Color string
	Type  LabelType

	ParentID string `json:",omitempty"`
}

type UpdateLabelReq struct {
	Name  string
	Color string

	ParentID string `json:",omitempty"`
}

type LabelType int

const (
	LabelTypeLabel LabelType = iota + 1
	LabelTypeContactGroup
	LabelTypeFolder
	LabelTypeSystem
)