package mapper

import (
	"go-humas-be/app/database/entity"
	res "go-humas-be/app/module/ppid_data_categories/response"
	"strconv"
)

func PpidDataCategoriesResponseMapper(ppidDataCategoriesReq *entity.PpidDataCategories, childPpidDataCategoriesReq []*entity.PpidDataCategories) (ppidDataCategoriesRes *res.PpidDataCategoriesResponse) {
	if ppidDataCategoriesReq != nil {
		var childPpidDataCategoriesRes []*res.PpidDataCategoriesResponse
		for _, item := range childPpidDataCategoriesReq {
			childPpidDataCategoriesRes = append(childPpidDataCategoriesRes, PpidDataCategoriesResponseMapper(item, nil))
		}

		ppidDataCategoriesRes = &res.PpidDataCategoriesResponse{
			ID:           ppidDataCategoriesReq.ID,
			Title:        ppidDataCategoriesReq.Title,
			Description:  ppidDataCategoriesReq.Description,
			Slug:         ppidDataCategoriesReq.Slug,
			ParentId:     ppidDataCategoriesReq.ParentId,
			ThumbnailUrl: "/ppid-data-categories/thumbnail/viewer/" + strconv.Itoa(int(ppidDataCategoriesReq.ID)),
			IsActive:     ppidDataCategoriesReq.IsActive,
			CreatedAt:    ppidDataCategoriesReq.CreatedAt,
			UpdatedAt:    ppidDataCategoriesReq.UpdatedAt,

			Children: childPpidDataCategoriesRes,
		}
	}
	return ppidDataCategoriesRes
}
