package mapper

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

func GalleryFilesResponseMapper(file *entity.GalleryFiles, host string) *res.GalleryFilesResponse {
	if file == nil {
		return nil
	}

	response := &res.GalleryFilesResponse{
		ID:        file.ID,
		GalleryID: file.GalleryID,
		Title:     file.Title,
		ImagePath: file.ImagePath,
		IsActive:  file.IsActive,
		CreatedAt: file.CreatedAt,
		UpdatedAt: file.UpdatedAt,
	}

	if file.ImagePath != nil && *file.ImagePath != "" {
		// Extract filename from path
		filename := filepath.Base(*file.ImagePath)
		imageUrl := host + "/gallery-files/viewer/" + filename
		response.ImageUrl = &imageUrl
	}

	return response
}

