package handlers

import "github.com/orchard9/rdev/internal/domain"

// QuestionDTO is the data transfer object for questions.
type QuestionDTO struct {
	ID             string            `json:"id"`
	ConversationID string            `json:"conversation_id"`
	ProjectID      string            `json:"project_id"`
	Type           string            `json:"type"`
	Text           string            `json:"text"`
	Choices        []string          `json:"choices,omitempty"`
	Answer         *string           `json:"answer,omitempty"`
	AnswerChoices  []string          `json:"answer_choices,omitempty"`
	Metadata       map[string]string `json:"metadata,omitempty"`
	CreatedAt      string            `json:"created_at"`
	AnsweredAt     *string           `json:"answered_at,omitempty"`
}

func toQuestionDTO(q *domain.Question) *QuestionDTO {
	if q == nil {
		return nil
	}
	dto := &QuestionDTO{
		ID:             string(q.ID),
		ConversationID: string(q.ConversationID),
		ProjectID:      q.ProjectID,
		Type:           string(q.Type),
		Text:           q.Text,
		Choices:        q.Choices,
		Answer:         q.Answer,
		AnswerChoices:  q.AnswerChoices,
		Metadata:       q.Metadata,
		CreatedAt:      q.CreatedAt.Format("2006-01-02T15:04:05Z07:00"),
	}
	if q.AnsweredAt != nil {
		ts := q.AnsweredAt.Format("2006-01-02T15:04:05Z07:00")
		dto.AnsweredAt = &ts
	}
	return dto
}
