package mapper

import (
	"narasi-ahli-be/app/database/entity"
	"narasi-ahli-be/app/module/research_journals/response"
)

func ResearchJournalsResponseMapper(researchJournal *entity.ResearchJournals) *response.ResearchJournalsResponse {
	result := &response.ResearchJournalsResponse{
		ID:            researchJournal.ID,
		UserID:        researchJournal.UserID,
		JournalTitle:  researchJournal.JournalTitle,
		Publisher:     researchJournal.Publisher,
		JournalURL:    researchJournal.JournalURL,
		PublishedDate: researchJournal.PublishedDate,
		CreatedAt:     researchJournal.CreatedAt,
		UpdatedAt:     researchJournal.UpdatedAt,
	}

	// Extract year from PublishedDate
	if researchJournal.PublishedDate != nil {
		year := researchJournal.PublishedDate.Year()
		result.PublishedYear = &year
	}

	if researchJournal.User != nil {
		result.User = &response.UserBasicInfo{
			ID:       researchJournal.User.ID,
			Username: researchJournal.User.Username,
			Fullname: researchJournal.User.Fullname,
			Email:    researchJournal.User.Email,
		}
	}

	return result
}
