package main

import (
	"context"
	"encoding/json"
	"fmt"
	"time"

	"github.com/aws/aws-sdk-go-v2/service/sqs/types"
	"github.com/google/uuid"
)

// HandleDummy is blissfully unaware of SQS, and could therefore be used as a handler for another message queue.
func HandleDummy(_ context.Context, enc *json.Encoder,
	msgID uuid.UUID, sentTime time.Time, msg []byte, meta map[string]types.MessageAttributeValue) error {
	type EventBody struct {
		EventID   uuid.UUID      `json:"event_id"`
		EventTime time.Time      `json:"event_time"`
		Data      map[string]int `json:"data,omitempty"`
		Meta      map[string]types.MessageAttributeValue
	}
	evt := EventBody{
		EventID:   msgID,
		EventTime: sentTime,
		Meta:      meta,
	}
	if err := json.Unmarshal(msg, &evt.Data); err != nil {
		return fmt.Errorf("error parsing body as JSON: %w", err)
	}

	enc.Encode(evt)
	return nil
}
