// Package converter provides pure field-mapping functions between store/model types and dto types.
// Naming convention:
//   - Forward (store→dto): ToXxx(m storeType) dto.Xxx  or  ToXxx(m *storeType) *dto.Xxx
//   - Reverse (dto→store): FromXxx(d *dtoType) *storeType
//   - Slice wrappers:      ToXxxList(items []storeType) []dto.Xxx
//
// Hard rules:
//   - This package must NOT import any internal/api/{domain} package (no reverse dependency).
//   - The parent dto package must NOT import this converter package.
//   - Preserve nil→nil and nil/empty slice behavior exactly as in original presenters.
package converter

import (
	"github.com/tidbcloud/AgentTeam/internal/api/dto"
	"github.com/tidbcloud/AgentTeam/internal/store/attachment"
)

// ToAppAttachments converts a slice of store attachments to DTO attachments.
// Deduplicated from agent/presenters.go, message/presenters.go, media/presenters.go.
// Preserves nil behavior: returns nil for nil/empty input (matches agent/message original behavior).
// Callers that need empty slice instead of nil should handle that at the call site.
func ToAppAttachments(attachments []attachment.AppAttachment) []dto.AppAttachment {
	if len(attachments) == 0 {
		return nil
	}
	items := make([]dto.AppAttachment, 0, len(attachments))
	for _, attachment := range attachments {
		items = append(items, dto.AppAttachment{
			ID:           attachment.ID,
			Filename:     attachment.Filename,
			ContentType:  attachment.ContentType,
			SizeBytes:    attachment.SizeBytes,
			ThumbnailURL: attachment.ThumbnailURL,
		})
	}
	return items
}

// ToPersonalStickers converts a slice of store personal stickers to DTO personal stickers.
// Migrated from media/presenters.go.
// Preserves empty-slice behavior: returns []dto.PersonalSticker{} (not nil) for empty input.
func ToPersonalStickers(stickers []attachment.PersonalSticker) []dto.PersonalSticker {
	if len(stickers) == 0 {
		return []dto.PersonalSticker{}
	}
	items := make([]dto.PersonalSticker, 0, len(stickers))
	for _, sticker := range stickers {
		items = append(items, dto.PersonalSticker{
			ID:          sticker.ID,
			Filename:    sticker.Filename,
			ContentType: sticker.ContentType,
			SizeBytes:   sticker.SizeBytes,
			CreatedAt:   sticker.CreatedAt,
		})
	}
	return items
}
