package mapper

import (
	"netidhub-saas-be/app/database/entity"
	res "netidhub-saas-be/app/module/article_files/response"
)

func ArticleFilesResponseMapper(articleFilesReq *entity.ArticleFiles, host string) (articleFilesRes *res.ArticleFilesResponse) {
	fileUrl := host + "/article-files/viewer/"
	if articleFilesReq.FileName != nil {
		fileUrl += *articleFilesReq.FileName
	}

	if articleFilesReq != nil {
		articleFilesRes = &res.ArticleFilesResponse{
			ID:            articleFilesReq.ID,
			ArticleId:     articleFilesReq.ArticleId,
			FilePath:      articleFilesReq.FilePath,
			FileUrl:       &fileUrl,
			FileName:      articleFilesReq.FileName,
			FileThumbnail: articleFilesReq.FileThumbnail,
			FileAlt:       articleFilesReq.FileAlt,
			WidthPixel:    articleFilesReq.WidthPixel,
			HeightPixel:   articleFilesReq.HeightPixel,
			Size:          articleFilesReq.Size,
			DownloadCount: articleFilesReq.DownloadCount,
			CreatedById:   articleFilesReq.CreatedById,
			StatusId:      articleFilesReq.StatusId,
			IsPublish:     articleFilesReq.IsPublish,
			PublishedAt:   articleFilesReq.PublishedAt,
			IsActive:      articleFilesReq.IsActive,
			CreatedAt:     articleFilesReq.CreatedAt,
			UpdatedAt:     articleFilesReq.UpdatedAt,
		}
	}
	return articleFilesRes
}
