package services

import (
	datasql "gitlab.ost.ch/marketminds/marketminds/pkg/data/sql"
	"gitlab.ost.ch/marketminds/marketminds/pkg/entity"
)

func (s *Service) GetAllNewsChannels() ([]*entity.NewsChannel, error) {
	session := datasql.NewSqlRepository(s.SqlInstance)
	newsChannels, err := session.GetAllNewsChannels()

	if err != nil {
		return nil, err
	}

	return newsChannels, nil
}

func (s *Service) GetNewsChannelById(id string) (*entity.NewsChannel, error) {
	session := datasql.NewSqlRepository(s.SqlInstance)

	nc, err := session.GetNewsChannelById(id)

	if err != nil {
		return nil, err
	}

	newsItems, err := session.GetByNewsChannelId(nc.Id)
	if err != nil {
		return nil, err
	}
	nc.NewsItems = newsItems

	return nc, nil
}
