package mapper

import (
	"58team_blog/internal/application/common"
	"58team_blog/internal/application/queries"
	"58team_blog/internal/domain/entities"
)

func CreatePostResultFromEntity(entity *entities.Post) *common.PostResult {
	return &common.PostResult{
		Id:          entity.Id,
		UserId:      entity.UserId,
		Title:       entity.Title,
		Description: entity.Description,
		Content:     entity.Content,
		CreatedAt:   entity.CreatedAt,
		UpdatedAt:   entity.UpdatedAt,
	}
}

func CreatePostResultListFromEntity(entity_list []*entities.Post) *common.PostResultList {
	var result common.PostResultList

	for _, e := range entity_list {
		result.Result = append(result.Result, CreatePostResultFromEntity(e))
	}

	return &result
}

func CreatePostFindByIdResultFromEntity(entity entities.Post) *queries.PostFindByIdResult {
	return &queries.PostFindByIdResult{
		Result: CreatePostResultFromEntity(&entity),
	}
}

func CreatePostFindAllByUserNameResult(entity []*entities.Post) *queries.PostFindAllByUserNameResult {
	return &queries.PostFindAllByUserNameResult{
		Result: CreatePostResultListFromEntity(entity),
	}
}

func CreatePostGetAllResult(entity_list []*entities.Post) *queries.PostGetAllResult {
	return &queries.PostGetAllResult{
		Result: CreatePostResultListFromEntity(entity_list),
	}
}
