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 PhasesRelationDTO struct {
	Id   uint   `json:"id"`
	Name string `json:"name"`
}

type PhasesListDTO struct {
	Id            uint                     `json:"id"`
	Name          string                   `json:"name"`
	Category      string                   `json:"category"`
	IsActive      bool                     `json:"is_active"`
	ActivityCount int                      `json:"activity_count"`
	CreatedUser   *userDTO.UserRelationDTO `json:"created_user"`
	CreatedAt     time.Time                `json:"created_at"`
}

type PhasesDetailDTO struct {
	PhasesListDTO
}

// === Mapper Functions ===

func ToPhasesRelationDTO(e entity.Phases) PhasesRelationDTO {
	return PhasesRelationDTO{
		Id:   e.Id,
		Name: e.Name,
	}
}

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

	return PhasesListDTO{
		Id:            e.Id,
		Name:          e.Name,
		Category:      e.Category,
		IsActive:      e.IsActive,
		ActivityCount: e.ActivityCount,
		CreatedAt:     e.CreatedAt,
		CreatedUser:   createdUser,
	}
}

func ToPhasesListDTOs(e []entity.Phases) []PhasesListDTO {
	result := make([]PhasesListDTO, len(e))
	for i, r := range e {
		result[i] = ToPhasesListDTO(r)
	}
	return result
}

func ToPhasesDetailDTO(e entity.Phases) PhasesDetailDTO {
	return PhasesDetailDTO{
		PhasesListDTO: ToPhasesListDTO(e),
	}
}
