package mapper

import (
	"jaecoo-be/app/database/entity"
	res "jaecoo-be/app/module/article_categories/response"
	"strconv"
	"strings"
)

func ArticleCategoriesResponseMapper(articleCategoriesReq *entity.ArticleCategories, host string) (articleCategoriesRes *res.ArticleCategoriesResponse) {
	if articleCategoriesReq != nil {
		articleCategoriesRes = &res.ArticleCategoriesResponse{
			ID:            articleCategoriesReq.ID,
			Title:         articleCategoriesReq.Title,
			Description:   articleCategoriesReq.Description,
			Slug:          articleCategoriesReq.Slug,
			ThumbnailPath: articleCategoriesReq.ThumbnailPath,
			ParentId:      articleCategoriesReq.ParentId,
			OldCategoryId: articleCategoriesReq.OldCategoryId,
			CreatedById:   articleCategoriesReq.CreatedById,
			StatusId:      articleCategoriesReq.StatusId,
			IsPublish:     articleCategoriesReq.IsPublish,
			PublishedAt:   articleCategoriesReq.PublishedAt,
			IsActive:      articleCategoriesReq.IsActive,
			CreatedAt:     articleCategoriesReq.CreatedAt,
			UpdatedAt:     articleCategoriesReq.UpdatedAt,
		}

		if articleCategoriesReq.Tags != nil {
			tagsValue := *articleCategoriesReq.Tags
			articleCategoriesRes.Tags = strings.Split(tagsValue, ",")
		}

		if articleCategoriesRes.ThumbnailPath != nil {
			articleCategoriesRes.ThumbnailUrl = host + "/article-categories/thumbnail/viewer/" + strconv.Itoa(int(articleCategoriesReq.ID))
		}
	}
	return articleCategoriesRes
}
