<commit_before>﻿using System.Linq;
using Contentful.Core.Models;
using StockportContentApi.ContentfulModels;
using StockportContentApi.Model;
using StockportContentApi.Repositories;
using StockportContentApi.Utils;

namespace StockportContentApi.ContentfulFactories
{
    public class ArticleContentfulFactory : IContentfulFactory<Entry<ContentfulArticle>, Article>
    {
        private readonly IContentfulFactory<ContentfulSection, Section> _sectionFactory;
        private readonly IContentfulFactory<Entry<ContentfulCrumb>, Crumb> _crumbFactory;
        private readonly IContentfulFactory<ContentfulProfile, Profile> _profileFactory;
        private readonly IContentfulFactory<Entry<ContentfulArticle>, Topic> _parentTopicFactory;
        private readonly IContentfulFactory<Asset, Document> _documentFactory;
        private readonly IVideoRepository _videoRepository;
        private readonly DateComparer _dateComparer;

        public ArticleContentfulFactory(IContentfulFactory<ContentfulSection, Section> sectionFactory, 
            IContentfulFactory<Entry<ContentfulCrumb>, Crumb> crumbFactory, 
            IContentfulFactory<ContentfulProfile, Profile> profileFactory, 
            IContentfulFactory<Entry<ContentfulArticle>, Topic> parentTopicFactory,
            IContentfulFactory<Asset, Document> documentFactory,
            IVideoRepository videoRepository,
            ITimeProvider timeProvider)
        {
            _sectionFactory = sectionFactory;
            _crumbFactory = crumbFactory;
            _profileFactory = profileFactory;
            _documentFactory = documentFactory;
            _videoRepository = videoRepository;
            _parentTopicFactory = parentTopicFactory;
            _dateComparer = new DateComparer(timeProvider);
        }

        public Article ToModel(Entry<ContentfulArticle> entryContentfulArticle)
        {
            var entry = entryContentfulArticle.Fields;

            var sections = entry.Sections.Where(section => ContentfulHelpers.EntryIsNotALink(section.SystemProperties))
                                         .Select(section => _sectionFactory.ToModel(section.Fields)).ToList();
            var breadcrumbs = entry.Breadcrumbs.Where(section => ContentfulHelpers.EntryIsNotALink(section.SystemProperties))
                                               .Select(crumb => _crumbFactory.ToModel(crumb)).ToList();

            var profiles = entry.Profiles.Where(section => ContentfulHelpers.EntryIsNotALink(section.SystemProperties))
                                         .Select(profile => _profileFactory.ToModel(profile.Fields)).ToList();

            var topic = _parentTopicFactory.ToModel(entryContentfulArticle) ?? new NullTopic();

            var documents = entry.Documents.Where(section => ContentfulHelpers.EntryIsNotALink(section.SystemProperties))<commit_msg>#836 David/Raj fixed Sunrise and Sunset date not working for sections<commit_after>﻿using System.Linq;
using Contentful.Core.Models;
using StockportContentApi.ContentfulModels;
using StockportContentApi.Model;
using StockportContentApi.Repositories;
using StockportContentApi.Utils;

namespace StockportContentApi.ContentfulFactories
{
    public class ArticleContentfulFactory : IContentfulFactory<Entry<ContentfulArticle>, Article>
    {
        private readonly IContentfulFactory<ContentfulSection, Section> _sectionFactory;
        private readonly IContentfulFactory<Entry<ContentfulCrumb>, Crumb> _crumbFactory;
        private readonly IContentfulFactory<ContentfulProfile, Profile> _profileFactory;
        private readonly IContentfulFactory<Entry<ContentfulArticle>, Topic> _parentTopicFactory;
        private readonly IContentfulFactory<Asset, Document> _documentFactory;
        private readonly IVideoRepository _videoRepository;
        private readonly DateComparer _dateComparer;

        public ArticleContentfulFactory(IContentfulFactory<ContentfulSection, Section> sectionFactory, 
            IContentfulFactory<Entry<ContentfulCrumb>, Crumb> crumbFactory, 
            IContentfulFactory<ContentfulProfile, Profile> profileFactory, 
            IContentfulFactory<Entry<ContentfulArticle>, Topic> parentTopicFactory,
            IContentfulFactory<Asset, Document> documentFactory,
            IVideoRepository videoRepository,
            ITimeProvider timeProvider)
        {
            _sectionFactory = sectionFactory;
            _crumbFactory = crumbFactory;
            _profileFactory = profileFactory;
            _documentFactory = documentFactory;
            _videoRepository = videoRepository;
            _parentTopicFactory = parentTopicFactory;
            _dateComparer = new DateComparer(timeProvider);
        }

        public Article ToModel(Entry<ContentfulArticle> entryContentfulArticle)
        {
            var entry = entryContentfulArticle.Fields;

            var sections = entry.Sections.Where(section => ContentfulHelpers.EntryIsNotALink(section.SystemProperties) && _dateComparer.DateNowIsWithinSunriseAndSunsetDates(section.Fields.SunriseDate, section.Fields.SunsetDate))
                                         .Select(section => _sectionFactory.ToModel(section.Fields)).ToList();
            var breadcrumbs = entry.Breadcrumbs.Where(section => ContentfulHelpers.EntryIsNotALink(section.SystemProperties))
                                               .Select(crumb => _crumbFactory.ToModel(crumb)).ToList();

            var profiles = entry.Profiles.Where(section => ContentfulHelpers.EntryIsNotALink(section.SystemProperties))
                                         .Select(profile => _profileFactory.ToModel(profile.Fields)).ToList();

            var topic = _parentTopicFactory.ToModel(entryContentfulArticle) ?? new NullTopic();

            var documents = entry.Documents.Where(section => ContentfulHelpers.EntryIsNotALink(section.SystemProperties))
{'fraction_non_alphanumeric': 0.06869580003400783, 'fraction_numerical': 0.0005101173269852066, 'mean_word_length': 3.4225563909774435, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 51, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4556895', 'n_tokens_mistral': 1390, 'n_tokens_neox': 1377, 'n_words': 253}