package response

import (
	"time"

	"gitlab.ost.ch/marketminds/marketminds/pkg/entity"
)

type newsChannel struct {
	Id            int64       `json:"id"`
	RssUrl        string      `json:"rss_url"`
	ImageUrl      string      `json:"image_url"`
	Title         string      `json:"title"`
	Link          string      `json:"link"`
	Description   string      `json:"description"`
	Language      string      `json:"language"`
	Copyright     string      `json:"copyright"`
	LastBuildDate string      `json:"last_build_date"`
	UpdatedAt     string      `json:"updated_at"`
	NewsItems     []*newsItem `json:"news_items"`
}

func newNewsChannel(newsChannelInput *entity.NewsChannel) *newsChannel {
	var newsItems []*newsItem

	if newsChannelInput.NewsItems != nil {
		newsItems = newNewsItems(newsChannelInput.NewsItems)
	}

	return &newsChannel{
		Id:            newsChannelInput.Id,
		RssUrl:        newsChannelInput.RssUrl,
		ImageUrl:      newsChannelInput.ImageUrl.String,
		Title:         newsChannelInput.Title,
		Link:          newsChannelInput.Link.String,
		Description:   newsChannelInput.Description.String,
		Language:      newsChannelInput.Language.String,
		Copyright:     newsChannelInput.Copyright.String,
		LastBuildDate: newsChannelInput.LastBuildDate.Time.UTC().Format(time.RFC3339),
		UpdatedAt:     newsChannelInput.UpdatedAt.UTC().Format(time.RFC3339),
		NewsItems:     newsItems,
	}
}
