package mapper

import (
	"jaecoo-be/app/database/entity"
	res "jaecoo-be/app/module/promotions/response"
	"path/filepath"
)

func PromotionsResponseMapper(promotion *entity.Promotions, host string) *res.PromotionsResponse {
	if promotion == nil {
		return nil
	}

	response := &res.PromotionsResponse{
		ID:            promotion.ID,
		Title:         promotion.Title,
		Description:   promotion.Description,
		ThumbnailPath: promotion.ThumbnailPath,
		IsActive:      promotion.IsActive,
		CreatedAt:     promotion.CreatedAt,
		UpdatedAt:     promotion.UpdatedAt,
	}

	if promotion.ThumbnailPath != nil && *promotion.ThumbnailPath != "" {
		// Extract filename from path
		filename := filepath.Base(*promotion.ThumbnailPath)
		thumbnailUrl := host + "/promotions/viewer/" + filename
		response.ThumbnailUrl = &thumbnailUrl
	}

	return response
}

