package notification

import (
	"time"

	"juwan-backend/app/notification/api/internal/types"
	"juwan-backend/app/notification/rpc/notificationservice"
)

func formatUnix(ts int64) string {
	if ts <= 0 {
		return ""
	}
	return time.Unix(ts, 0).UTC().Format(time.RFC3339)
}

func toAPINotification(n *notificationservice.Notifications) types.Notification {
	return types.Notification{
		Id:        n.GetId(),
		Type:      n.GetType(),
		Title:     n.GetTitle(),
		Content:   n.GetContent(),
		Read:      n.GetRead(),
		Link:      n.GetLink(),
		CreatedAt: formatUnix(n.GetCreatedAt()),
	}
}
