package document_scraper

import (
	"strings"

	"tm/internal/tender"
)

// BuildDocumentScraperTenderResponse maps a stored tender to the scraper API contract.
func BuildDocumentScraperTenderResponse(t *tender.Tender) *DocumentScraperTenderResponse {
	if t == nil {
		return &DocumentScraperTenderResponse{}
	}

	documentURL := strings.TrimSpace(t.DocumentURI)
	if documentURL == "" {
		documentURL = strings.TrimSpace(t.TenderURL)
	}

	return &DocumentScraperTenderResponse{
		ContractFolderID:    t.ContractFolderID,
		NoticePublicationID: t.NoticePublicationID,
		DocumentURL:         documentURL,
		Title:               t.Title,
		Description:         t.Description,
	}
}
