package dto

import (
	"time"

	entity "gitlab.com/mbugroup/lti-api.git/internal/entities"
	userDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/users/dto"
)

// === DTO Structs ===

type PhaseActivityRelationDTO struct {
	Id   uint   `json:"id"`
	Name string `json:"name"`
}

type PhaseActivityListDTO struct {
	Id          uint                     `json:"id"`
	PhaseId     uint                     `json:"phase_id"`
	Name        string                   `json:"name"`
	Description *string                  `json:"description"`
	TimeType    *string                  `json:"time_type"`
	CreatedUser *userDTO.UserRelationDTO `json:"created_user"`
	CreatedAt   time.Time                `json:"created_at"`
	UpdatedAt   time.Time                `json:"updated_at"`
}

type PhaseActivityDetailDTO struct {
	PhaseActivityListDTO
}

// === Mapper Functions ===

func ToPhaseActivityRelationDTO(e entity.PhaseActivity) PhaseActivityRelationDTO {
	return PhaseActivityRelationDTO{
		Id:   e.Id,
		Name: e.Name,
	}
}

func ToPhaseActivityListDTO(e entity.PhaseActivity) PhaseActivityListDTO {
	var createdUser *userDTO.UserRelationDTO
	// if e.CreatedUser.Id != 0 {
	// 	mapped := userDTO.ToUserRelationDTO(e.CreatedUser)
	// 	createdUser = &mapped
	// }

	return PhaseActivityListDTO{
		Id:          e.Id,
		PhaseId:     e.PhaseId,
		Name:        e.Name,
		Description: e.Description,
		TimeType:    e.TimeType,
		CreatedAt:   e.CreatedAt,
		UpdatedAt:   e.UpdatedAt,
		CreatedUser: createdUser,
	}
}

func ToPhaseActivityListDTOs(e []entity.PhaseActivity) []PhaseActivityListDTO {
	result := make([]PhaseActivityListDTO, len(e))
	for i, r := range e {
		result[i] = ToPhaseActivityListDTO(r)
	}
	return result
}

func ToPhaseActivityDetailDTO(e entity.PhaseActivity) PhaseActivityDetailDTO {
	return PhaseActivityDetailDTO{
		PhaseActivityListDTO: ToPhaseActivityListDTO(e),
	}
}
