package mzap

import (
	me "github.com/tech/sendico/pkg/messaging/envelope"
	"go.uber.org/zap"
	"go.uber.org/zap/zapcore"
)

type envelopeMarshaler struct {
	me.Envelope
}

func (e envelopeMarshaler) MarshalLogObject(enc zapcore.ObjectEncoder) error {
	enc.AddString("message_id", e.GetMessageId().String())
	enc.AddString("sender", e.GetSender())
	enc.AddTime("time_stamp", e.GetTimeStamp())
	enc.AddString("type", e.GetSignature().StringType())
	enc.AddString("action", e.GetSignature().StringAction())
	return nil
}

func Envelope(envelope me.Envelope) zap.Field {
	return zap.Object("envelope", envelopeMarshaler{envelope})
}
