package proto

import (
	

	
	
	pbv2 

	
)

const RecordDomain = "libp2p-relay-rsvp"

// TODO: register in multicodec table in https://github.com/multiformats/multicodec
var RecordCodec = []byte{0x03, 0x02}

func init() {
	record.RegisterType(&ReservationVoucher{})
}

type ReservationVoucher struct {
	// Relay is the ID of the peer providing relay service
	Relay peer.ID
	// Peer is the ID of the peer receiving relay service through Relay
	Peer peer.ID
	// Expiration is the expiration time of the reservation
	Expiration time.Time
}

var _ record.Record = (*ReservationVoucher)(nil)

func ( *ReservationVoucher) () string {
	return RecordDomain
}

func ( *ReservationVoucher) () []byte {
	return RecordCodec
}

func ( *ReservationVoucher) () ([]byte, error) {
	 := uint64(.Expiration.Unix())
	return proto.Marshal(&pbv2.ReservationVoucher{
		Relay:      []byte(.Relay),
		Peer:       []byte(.Peer),
		Expiration: &,
	})
}

func ( *ReservationVoucher) ( []byte) error {
	 := pbv2.ReservationVoucher{}
	 := proto.Unmarshal(, &)
	if  != nil {
		return 
	}

	.Relay,  = peer.IDFromBytes(.GetRelay())
	if  != nil {
		return 
	}

	.Peer,  = peer.IDFromBytes(.GetPeer())
	if  != nil {
		return 
	}

	.Expiration = time.Unix(int64(.GetExpiration()), 0)
	return nil
}