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

type RecordingListDTO struct {
	RecordingBaseDTO
	CreatedUser *userDTO.UserBaseDTO `json:"created_user"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

type RecordingDetailDTO struct {
	RecordingListDTO
}

// === Mapper Functions ===

func ToRecordingBaseDTO(e entity.Recording) RecordingBaseDTO {
	return RecordingBaseDTO{
		Id:    e.Id,
		Name:  e.Name,
	}
}

func ToRecordingListDTO(e entity.Recording) RecordingListDTO {
	var createdUser *userDTO.UserBaseDTO
	if e.CreatedUser.Id != 0 {
		mapped := userDTO.ToUserBaseDTO(e.CreatedUser)
		createdUser = &mapped
	}

	return RecordingListDTO{
		RecordingBaseDTO: ToRecordingBaseDTO(e),
		CreatedAt:   e.CreatedAt,
		UpdatedAt:   e.UpdatedAt,
		CreatedUser: createdUser,
	}
}

func ToRecordingListDTOs(e []entity.Recording) []RecordingListDTO {
	result := make([]RecordingListDTO, len(e))
	for i, r := range e {
		result[i] = ToRecordingListDTO(r)
	}
	return result
}

func ToRecordingDetailDTO(e entity.Recording) RecordingDetailDTO {
	return RecordingDetailDTO{
		RecordingListDTO: ToRecordingListDTO(e),
	}
}
