package entity

import (
	"database/sql"
	"time"
)

type NewsItem struct {
	Id              int64          `json:"id"`
	Title           string         `json:"title"`
	Description     sql.NullString `json:"description"`
	ThumbnailUrl    sql.NullString `json:"thumbnail_url"`
	Link            sql.NullString `json:"link"`
	PubDate         sql.NullTime   `json:"pub_date"`
	Category        sql.NullString `json:"category"`
	Guid            sql.NullString `json:"guid"`
	EnclosureUrl    sql.NullString `json:"enclosure_url"`
	MediaCopyright  sql.NullString `json:"media_copyright"`
	MediaTitle      sql.NullString `json:"media_title"`
	Version         sql.NullString `json:"version"`
	CreatedAt       time.Time      `json:"created_at"`
	NewsChannelId   int64          `json:"news_channel_id"`
	NewsChannel     *NewsChannel
	SentimentResult *SentimentResult
	NERResult       []*NERResult
}

func NewNewsItem(
	id int,
	title string,
	description string,
	thumbnailUrl string,
	link string,
	pubDate time.Time,
	category,
	guid,
	enclosureUrl,
	mediaCopyright,
	mediaTitle,
	version string,
	createdAt time.Time,
	newsChannelId int64,
) *NewsItem {
	return &NewsItem{
		Id:             int64(id),
		Title:          title,
		Description:    sql.NullString{String: description, Valid: true},
		ThumbnailUrl:   sql.NullString{String: thumbnailUrl, Valid: true},
		Link:           sql.NullString{String: link, Valid: true},
		PubDate:        sql.NullTime{Time: pubDate, Valid: true},
		Category:       sql.NullString{String: category, Valid: true},
		Guid:           sql.NullString{String: guid, Valid: true},
		EnclosureUrl:   sql.NullString{String: enclosureUrl, Valid: true},
		MediaCopyright: sql.NullString{String: mediaCopyright, Valid: true},
		MediaTitle:     sql.NullString{String: mediaTitle, Valid: true},
		Version:        sql.NullString{String: version, Valid: true},
		CreatedAt:      createdAt,
		NewsChannelId:  newsChannelId,
	}
}
