package mapper

import (
	"campaign-pool-be/app/database/entity"
	res "campaign-pool-be/app/module/magazine_files/response"
)

func MagazineFilesResponseMapper(magazineFilesReq *entity.MagazineFiles, host string) (magazineFilesRes *res.MagazineFilesResponse) {
	fileUrl := host + "/magazine-files/viewer/"
	if magazineFilesReq.FileName != nil {
		fileUrl += *magazineFilesReq.FileName
	}

	if magazineFilesReq != nil {
		magazineFilesRes = &res.MagazineFilesResponse{
			ID:            magazineFilesReq.ID,
			Title:         magazineFilesReq.Title,
			Description:   magazineFilesReq.Description,
			MagazineId:    magazineFilesReq.MagazineId,
			DownloadCount: magazineFilesReq.DownloadCount,
			FilePath:      magazineFilesReq.FilePath,
			FileUrl:       &fileUrl,
			FileName:      magazineFilesReq.FileName,
			FileAlt:       magazineFilesReq.FileAlt,
			WidthPixel:    magazineFilesReq.WidthPixel,
			HeightPixel:   magazineFilesReq.HeightPixel,
			Size:          magazineFilesReq.Size,
			StatusId:      magazineFilesReq.StatusId,
			IsPublish:     magazineFilesReq.IsPublish,
			PublishedAt:   magazineFilesReq.PublishedAt,
			IsActive:      magazineFilesReq.IsActive,
			CreatedAt:     magazineFilesReq.CreatedAt,
			UpdatedAt:     magazineFilesReq.UpdatedAt,
		}
	}
	return magazineFilesRes
}
