package mapper

import (
	"github.com/google/uuid"
	"web-qudo-be/app/database/entity"
	res "web-qudo-be/app/module/article_comments/response"
	usersRepository "web-qudo-be/app/module/users/repository"
)

func ArticleCommentsResponseMapper(clientId *uuid.UUID, articleCommentsReq *entity.ArticleComments, usersRepo usersRepository.UsersRepository) (articleCommentsRes *res.ArticleCommentsResponse) {
	if articleCommentsReq != nil {

		commentFromName := ""
		if articleCommentsReq.CommentFrom != nil {
			findUser, _ := usersRepo.FindOne(clientId, *articleCommentsReq.CommentFrom)
			if findUser != nil {
				commentFromName = findUser.Fullname
			}
		}

		articleCommentsRes = &res.ArticleCommentsResponse{
			ID:              articleCommentsReq.ID,
			Message:         articleCommentsReq.Message,
			ArticleId:       articleCommentsReq.ArticleId,
			CommentFromId:   articleCommentsReq.CommentFrom,
			CommentFromName: &commentFromName,
			ParentId:        articleCommentsReq.ParentId,
			IsPublic:        articleCommentsReq.IsPublic,
			StatusId:        articleCommentsReq.StatusId,
			IsActive:        articleCommentsReq.IsActive,
			CreatedAt:       articleCommentsReq.CreatedAt,
			UpdatedAt:       articleCommentsReq.UpdatedAt,
		}
	}
	return articleCommentsRes
}
