package mappers

import (
	"actatempus_backend/internal/application/services/dto"
	"actatempus_backend/internal/domain/entities"
	"actatempus_backend/internal/utils"
	"time"
)

// MapTimeEntryToDTO converts a TimeEntry domain object to a TimeEntryDTO.
func MapTimeEntryToDTO(entry entities.TimeEntry) dto.TimeEntryDTO {
	return dto.TimeEntryDTO{
		ID:          entry.ID,
		StartTime:   entry.StartTime.Format(time.RFC3339),
		EndTime:     utils.Let(entry.EndTime, func (t time.Time) string { return t.Format(time.RFC3339);}),
		Description: entry.Description,
		UserID:      entry.UserID,
		ProjectID:   entry.ProjectID,
		CreatedAt:   entry.CreatedAt.Format(time.RFC3339),
		UpdatedAt:   entry.UpdatedAt.Format(time.RFC3339),
	}
}

// MapCreateDTOToTimeEntry converts a TimeEntryCreateDTO to a TimeEntry domain object.
func MapCreateDTOToTimeEntry(dto dto.TimeEntryCreateDTO) entities.TimeEntryCreate {
	
	return entities.TimeEntryCreate{
		StartTime:   parseISOTime(dto.StartTime),
		EndTime:     utils.Let(dto.EndTime,parseISOTime),
		Description: dto.Description,
		UserID:      dto.UserID,
		ProjectID:   dto.ProjectID,
	}
}

// MapUpdateDTOToTimeEntry converts a TimeEntryUpdateDTO to a partial TimeEntry domain object.
func MapUpdateDTOToTimeEntry(dto dto.TimeEntryUpdateDTO, ID string) entities.TimeEntryUpdate {
	return entities.TimeEntryUpdate{
		ID:          ID,
		StartTime:   utils.Let(dto.StartTime,parseISOTime),
		EndTime:     utils.Let(dto.EndTime,parseISOTime),
		Description: dto.Description,
		UserID:      dto.UserID,
		ProjectID:   dto.ProjectID,
	}
}
