// Code generated by protoc-gen-pico. DO NOT EDIT.
// source: types.proto
//
// versions:
//     protoc-gen-pico: v0.0.1
//     protoc:          v3.12.4

package macaroon

import (
	time "time"

	picobuf "storj.io/picobuf"
	picoconv "storj.io/picobuf/picoconv"
)

type Caveat struct {
	DisallowReads   bool           `json:"disallow_reads,omitempty"`
	DisallowWrites  bool           `json:"disallow_writes,omitempty"`
	DisallowLists   bool           `json:"disallow_lists,omitempty"`
	DisallowDeletes bool           `json:"disallow_deletes,omitempty"`
	DisallowLocks   bool           `json:"disallow_locks,omitempty"`
	AllowedPaths    []*Caveat_Path `json:"allowed_paths,omitempty"`
	NotAfter        *time.Time     `json:"not_after,omitempty"`
	NotBefore       *time.Time     `json:"not_before,omitempty"`
	MaxObjectTtl    *time.Duration `json:"max_object_ttl,omitempty"`
	Nonce           []byte         `json:"nonce,omitempty"`
}

func (m *Caveat) Encode(c *picobuf.Encoder) bool {
	if m == nil {
		return false
	}
	c.Bool(1, &m.DisallowReads)
	c.Bool(2, &m.DisallowWrites)
	c.Bool(3, &m.DisallowLists)
	c.Bool(4, &m.DisallowDeletes)
	c.Bool(5, &m.DisallowLocks)
	for _, x := range m.AllowedPaths {
		c.AlwaysMessage(10, x.Encode)
	}
	(*picoconv.Timestamp)(m.NotAfter).PicoEncode(c, 20)
	(*picoconv.Timestamp)(m.NotBefore).PicoEncode(c, 21)
	(*picoconv.Duration)(m.MaxObjectTtl).PicoEncode(c, 22)
	c.Bytes(30, &m.Nonce)
	return true
}

func (m *Caveat) Decode(c *picobuf.Decoder) {
	if m == nil {
		return
	}
	c.Bool(1, &m.DisallowReads)
	c.Bool(2, &m.DisallowWrites)
	c.Bool(3, &m.DisallowLists)
	c.Bool(4, &m.DisallowDeletes)
	c.Bool(5, &m.DisallowLocks)
	c.RepeatedMessage(10, func(c *picobuf.Decoder) {
		x := new(Caveat_Path)
		c.Loop(x.Decode)
		m.AllowedPaths = append(m.AllowedPaths, x)
	})
	if c.PendingField() == 20 {
		if m.NotAfter == nil {
			m.NotAfter = new(time.Time)
		}
		(*picoconv.Timestamp)(m.NotAfter).PicoDecode(c, 20)
	}
	if c.PendingField() == 21 {
		if m.NotBefore == nil {
			m.NotBefore = new(time.Time)
		}
		(*picoconv.Timestamp)(m.NotBefore).PicoDecode(c, 21)
	}
	if c.PendingField() == 22 {
		if m.MaxObjectTtl == nil {
			m.MaxObjectTtl = new(time.Duration)
		}
		(*picoconv.Duration)(m.MaxObjectTtl).PicoDecode(c, 22)
	}
	c.Bytes(30, &m.Nonce)
}

type Caveat_Path struct {
	Bucket              []byte `json:"bucket,omitempty"`
	EncryptedPathPrefix []byte `json:"encrypted_path_prefix,omitempty"`
}

func (m *Caveat_Path) Encode(c *picobuf.Encoder) bool {
	if m == nil {
		return false
	}
	c.Bytes(1, &m.Bucket)
	c.Bytes(2, &m.EncryptedPathPrefix)
	return true
}

func (m *Caveat_Path) Decode(c *picobuf.Decoder) {
	if m == nil {
		return
	}
	c.Bytes(1, &m.Bucket)
	c.Bytes(2, &m.EncryptedPathPrefix)
}
