package mapper

import (
	"web-qudo-be/app/database/entity"
	"web-qudo-be/app/module/bookmarks/response"
)

func ToBookmarksResponse(bookmark *entity.Bookmarks) *response.BookmarksResponse {
	return &response.BookmarksResponse{
		ID:        bookmark.ID,
		UserId:    bookmark.UserId,
		ArticleId: bookmark.ArticleId,
		IsActive:  bookmark.IsActive,
		CreatedAt: bookmark.CreatedAt,
		UpdatedAt: bookmark.UpdatedAt,
		Article: response.ArticleDetails{
			ID:              bookmark.Article.ID,
			Title:           bookmark.Article.Title,
			Slug:            bookmark.Article.Slug,
			Description:     bookmark.Article.Description,
			HtmlDescription: bookmark.Article.HtmlDescription,
			CategoryId:      bookmark.Article.CategoryId,
			TypeId:          bookmark.Article.TypeId,
			Tags:            bookmark.Article.Tags,
			ThumbnailUrl:    getThumbnailUrl(bookmark.Article.ThumbnailPath),
			PageUrl:         bookmark.Article.PageUrl,
			CreatedById:     bookmark.Article.CreatedById,
			ShareCount:      bookmark.Article.ShareCount,
			ViewCount:       bookmark.Article.ViewCount,
			CommentCount:    bookmark.Article.CommentCount,
			StatusId:        bookmark.Article.StatusId,
			IsBanner:        bookmark.Article.IsBanner,
			IsPublish:       bookmark.Article.IsPublish,
			PublishedAt:     bookmark.Article.PublishedAt,
			IsActive:        bookmark.Article.IsActive,
			CreatedAt:       bookmark.Article.CreatedAt,
			UpdatedAt:       bookmark.Article.UpdatedAt,
		},
	}
}

func ToBookmarksResponseList(bookmarks []entity.Bookmarks) []*response.BookmarksResponse {
	var responses []*response.BookmarksResponse
	for _, bookmark := range bookmarks {
		responses = append(responses, ToBookmarksResponse(&bookmark))
	}
	return responses
}

func getThumbnailUrl(thumbnailPath *string) string {
	if thumbnailPath != nil && *thumbnailPath != "" {
		return *thumbnailPath
	}
	return ""
}
