1package api
2
3import (
4	"strings"
5	"time"
6)
7
8// DirectoriesResponse is the response for https://sia.tech/docs/#renter-dir-siapath-get
9type DirectoriesResponse struct {
10	Directories []DirectoryInfo `json:"directories"`
11	Files       []FileInfo      `json:"files"`
12}
13
14// FilesResponse is the response for https://sia.tech/docs/#renter-files-get
15type FilesResponse struct {
16	Files []FileInfo `json:"files"`
17}
18
19// FileResponse is the response for https://sia.tech/docs/#renter-file-siapath-get
20type FileResponse struct {
21	File FileInfo `json:"file"`
22}
23
24// FileInfo is used in https://sia.tech/docs/#renter-files-get
25type FileInfo struct {
26	AccessTime       time.Time `json:"accesstime"`
27	Available        bool      `json:"available"`
28	ChangeTime       time.Time `json:"changetime"`
29	CipherType       string    `json:"ciphertype"`
30	CreateTime       time.Time `json:"createtime"`
31	Expiration       uint64    `json:"expiration"`
32	Filesize         uint64    `json:"filesize"`
33	Health           float64   `json:"health"`
34	LocalPath        string    `json:"localpath"`
35	MaxHealth        float64   `json:"maxhealth"`
36	MaxHealthPercent float64   `json:"maxhealthpercent"`
37	ModTime          time.Time `json:"modtime"`
38	NumStuckChunks   uint64    `json:"numstuckchunks"`
39	OnDisk           bool      `json:"ondisk"`
40	Recoverable      bool      `json:"recoverable"`
41	Redundancy       float64   `json:"redundancy"`
42	Renewing         bool      `json:"renewing"`
43	SiaPath          string    `json:"siapath"`
44	Stuck            bool      `json:"stuck"`
45	StuckHealth      float64   `json:"stuckhealth"`
46	UploadedBytes    uint64    `json:"uploadedbytes"`
47	UploadProgress   float64   `json:"uploadprogress"`
48}
49
50// DirectoryInfo is used in https://sia.tech/docs/#renter-dir-siapath-get
51type DirectoryInfo struct {
52	AggregateHealth              float64   `json:"aggregatehealth"`
53	AggregateLastHealthCheckTime time.Time `json:"aggregatelasthealthchecktime"`
54	AggregateMaxHealth           float64   `json:"aggregatemaxhealth"`
55	AggregateMaxHealthPercentage float64   `json:"aggregatemaxhealthpercentage"`
56	AggregateMinRedundancy       float64   `json:"aggregateminredundancy"`
57	AggregateMostRecentModTime   time.Time `json:"aggregatemostrecentmodtime"`
58	AggregateNumFiles            uint64    `json:"aggregatenumfiles"`
59	AggregateNumStuckChunks      uint64    `json:"aggregatenumstuckchunks"`
60	AggregateNumSubDirs          uint64    `json:"aggregatenumsubdirs"`
61	AggregateSize                uint64    `json:"aggregatesize"`
62	AggregateStuckHealth         float64   `json:"aggregatestuckhealth"`
63
64	Health              float64   `json:"health"`
65	LastHealthCheckTime time.Time `json:"lasthealthchecktime"`
66	MaxHealthPercentage float64   `json:"maxhealthpercentage"`
67	MaxHealth           float64   `json:"maxhealth"`
68	MinRedundancy       float64   `json:"minredundancy"`
69	MostRecentModTime   time.Time `json:"mostrecentmodtime"`
70	NumFiles            uint64    `json:"numfiles"`
71	NumStuckChunks      uint64    `json:"numstuckchunks"`
72	NumSubDirs          uint64    `json:"numsubdirs"`
73	SiaPath             string    `json:"siapath"`
74	Size                uint64    `json:"size"`
75	StuckHealth         float64   `json:"stuckhealth"`
76}
77
78// Error contains an error message per https://sia.tech/docs/#error
79type Error struct {
80	Message    string `json:"message"`
81	Status     string
82	StatusCode int
83}
84
85// Error returns a string for the error and satisfies the error interface
86func (e *Error) Error() string {
87	var out []string
88	if e.Message != "" {
89		out = append(out, e.Message)
90	}
91	if e.Status != "" {
92		out = append(out, e.Status)
93	}
94	if len(out) == 0 {
95		return "Siad Error"
96	}
97	return strings.Join(out, ": ")
98}
99