package mapper

import (
	"go-humas-be/app/database/entity"
	res "go-humas-be/app/module/ppid_data_approval_histories/response"

	usersRepository "go-humas-be/app/module/users/repository"
)

func PpidDataApprovalHistoriesResponseMapper(ppidDataApprovalHistoriesReq *entity.PpidDataApprovalHistories, usersRepo usersRepository.UsersRepository) (ppidDataApprovalHistoriesRes *res.PpidDataApprovalHistoriesResponse) {
	if ppidDataApprovalHistoriesReq != nil {
		findUser, _ := usersRepo.FindOne(ppidDataApprovalHistoriesReq.ApprovalBy)
		createdByName := ""
		if findUser != nil {
			createdByName = findUser.Fullname
		}

		ppidDataApprovalHistoriesRes = &res.PpidDataApprovalHistoriesResponse{
			ID:               ppidDataApprovalHistoriesReq.ID,
			Message:          ppidDataApprovalHistoriesReq.Message,
			ApprovalStatusId: ppidDataApprovalHistoriesReq.ApprovalStatusId,
			PpidDataId:       ppidDataApprovalHistoriesReq.PpidDataId,
			ApprovalById:     ppidDataApprovalHistoriesReq.ApprovalBy,
			ApprovalByName:   createdByName,
			ApprovalAtLevel:  ppidDataApprovalHistoriesReq.ApprovalAtLevel,
			IsActive:         ppidDataApprovalHistoriesReq.IsActive,
			CreatedAt:        ppidDataApprovalHistoriesReq.CreatedAt,
			UpdatedAt:        ppidDataApprovalHistoriesReq.UpdatedAt,
		}
	}
	return ppidDataApprovalHistoriesRes
}
