package mapper

import (
	"web-qudo-be/app/database/entity/users"
	userLevelsRepository "web-qudo-be/app/module/user_levels/repository"
	res "web-qudo-be/app/module/users/response"

	"github.com/google/uuid"
)

func UsersResponseMapper(usersReq *users.Users, userLevelsRepo userLevelsRepository.UserLevelsRepository, clientId *uuid.UUID) (usersRes *res.UsersResponse) {
	if usersReq != nil {
		findUserLevel, _ := userLevelsRepo.FindOne(clientId, usersReq.UserLevelId)
		userLevelGroup := ""
		if findUserLevel != nil {
			userLevelGroup = findUserLevel.AliasName
		}

		usersRes = &res.UsersResponse{
			ID:                 usersReq.ID,
			Username:           usersReq.Username,
			Email:              usersReq.Email,
			Fullname:           usersReq.Fullname,
			Address:            usersReq.Address,
			PhoneNumber:        usersReq.PhoneNumber,
			WorkType:           usersReq.WorkType,
			GenderType:         usersReq.GenderType,
			IdentityType:       usersReq.IdentityType,
			IdentityNumber:     usersReq.IdentityNumber,
			DateOfBirth:        usersReq.DateOfBirth,
			LastEducation:      usersReq.LastEducation,
			KeycloakId:         usersReq.KeycloakId,
			UserRoleId:         usersReq.UserRoleId,
			UserLevelGroup:     userLevelGroup,
			StatusId:           usersReq.StatusId,
			UserLevelId:        usersReq.UserLevelId,
			CreatedById:        usersReq.CreatedById,
			ProfilePicturePath: usersReq.ProfilePicturePath,
			IsActive:           usersReq.IsActive,
			CreatedAt:          usersReq.CreatedAt,
			UpdatedAt:          usersReq.UpdatedAt,
		}
	}
	return usersRes
}
