<commit_before>﻿namespace TraktApiSharp.Objects.Post.Syncs.Watchlist
{
    using Get.Movies;
    using Get.Shows;
    using Get.Shows.Episodes;
    using Newtonsoft.Json;
    using System;
    using System.Collections.Generic;
    using System.Linq;

    /// <summary>
    /// A Trakt watchlist post, containing all movies, shows and / or episodes,
    /// which should be added to the user's watchlist.
    /// </summary>
    public class TraktSyncWatchlistPost
    {
        /// <summary>
        /// An optional list of <see cref="TraktSyncWatchlistPostMovie" />s.
        /// <para>Each <see cref="TraktSyncWatchlistPostMovie" /> must have at least a valid Trakt id.</para>
        /// </summary>
        [JsonProperty(PropertyName = "movies")]
        public IEnumerable<TraktSyncWatchlistPostMovie> Movies { get; set; }

        /// <summary>
        /// An optional list of <see cref="TraktSyncWatchlistPostShow" />s.
        /// <para>Each <see cref="TraktSyncWatchlistPostShow" /> must have at least a valid Trakt id.</para>
        /// </summary>
        [JsonProperty(PropertyName = "shows")]
        public IEnumerable<TraktSyncWatchlistPostShow> Shows { get; set; }

        /// <summary>
        /// An optional list of <see cref="TraktSyncWatchlistPostEpisode" />s.
        /// <para>Each <see cref="TraktSyncWatchlistPostEpisode" /> must have at least a valid Trakt id.</para>
        /// </summary>
        [JsonProperty(PropertyName = "episodes")]
        public IEnumerable<TraktSyncWatchlistPostEpisode> Episodes { get; set; }

        /// <summary>Returns a new <see cref="TraktSyncWatchlistPostBuilder" /> instance.</summary>
        /// <returns>A new <see cref="TraktSyncWatchlistPostBuilder" /> instance.</returns>
        public static TraktSyncWatchlistPostBuilder Builder() => new TraktSyncWatchlistPostBuilder();
    }

    /// <summary>
    /// This is a helper class to build a <see cref="TraktSyncWatchlistPost" />.
    /// <para>
    /// It is recommended to use this class to build a watchlist post.<para /> 
    /// An instance of this class can be obtained with <see cref="TraktSyncWatchlistPost.Builder()" />.
    /// </para>
    /// </summary>
    public class TraktSyncWatchlistPostBuilder
    {
        private TraktSyncWatchlistPost _watchlistPost;

        /// <summary>Initializes a new instance of the <see cref="TraktSyncWatchlistPostBuilder" /> class.</summary>
        public TraktSyncWatchlistPostBuilder()
        {
            _watchlistPost = new TraktSyncWatchlistPost();
        }

        /// <summary>Adds a <see cref="TraktMovie" />, which will be added to the watchlist post.</summary>
        /// <param name="movie">The Trakt movie, which will be added.</param>
        /// <returns>The current <see cref="TraktSyncWatchlistPostBuilder" /> instance.</returns>
        /// <exception cref="ArgumentNullException">
        /// Thrown, if the given movie is null.
        /// Thrown, if the given movie ids are null.
        /// </exception>
        /// <exception cref="ArgumentException">
        /// Thrown, if the given movie has no valid ids set.
        /// Thrown, if the given movie has an year set, which has more or less than four digits.
        /// </exception>
        public TraktSyncWatchlistPostBuilder AddMovie(TraktMovie movie)
        {
            if (movie == null)
                throw new ArgumentNullException(nameof(movie));

            if (movie.Ids == null)
                throw new ArgumentNullException(nameof(movie.Ids));

            if (!movie.Ids.HasAnyId)
                throw new ArgumentException("no movie ids set or valid", nameof(movie.Ids));

            if (movie.Year.HasValue && movie.Year.Value.ToString().Length != 4)
                throw new ArgumentException("movie year not valid", nameof(movie.Year));

            EnsureMoviesListExists();

            var existingMovie = _watchlistPost.Movies.Where(m => m.Ids == movie.Ids).FirstOrDefault();

            if (existingMovie != null)
                return this;

            (_watchlistPost.Movies as List<TraktSyncWatchlistPostMovie>).Add(
                new TraktSyncWatchlistPostMovie
                {
                    Ids = movie.Ids,
                    Title = movie.Title,
                    Year = movie.Year
                });

            return this;
        }

        public TraktSyncWatchlistPostBuilder AddMovies(IEnumerable<TraktMovie> movies)
        {
            return this;
        }

        /// <summary>Adds a <see cref="TraktShow" />, which will be added to the watchlist post.</summary>
        /// <param name="show">The Trakt show, which will be added.</param>
        /// <returns>The current <see cref="TraktSyncWatchlistPostBuilder" /> instance.</returns>
        /// <exception cref="ArgumentNullException">
        /// Thrown, if the given show is null.
        /// Thrown, if the given show ids are null.
        /// </exception>
        /// <exception cref="ArgumentException">
        /// Thrown, if the given show has no valid ids set.
        /// Thrown, if the given show has an year set, which has more or less than four digits.
        /// </exception>
        public TraktSyncWatchlistPostBuilder AddShow(TraktShow show)
        {
            ValidateShow(show);<commit_msg>Add implementation for AddMovies method in TraktSyncWatchlistPostBuilder<commit_after>﻿namespace TraktApiSharp.Objects.Post.Syncs.Watchlist
{
    using Get.Movies;
    using Get.Shows;
    using Get.Shows.Episodes;
    using Newtonsoft.Json;
    using System;
    using System.Collections.Generic;
    using System.Linq;

    /// <summary>
    /// A Trakt watchlist post, containing all movies, shows and / or episodes,
    /// which should be added to the user's watchlist.
    /// </summary>
    public class TraktSyncWatchlistPost
    {
        /// <summary>
        /// An optional list of <see cref="TraktSyncWatchlistPostMovie" />s.
        /// <para>Each <see cref="TraktSyncWatchlistPostMovie" /> must have at least a valid Trakt id.</para>
        /// </summary>
        [JsonProperty(PropertyName = "movies")]
        public IEnumerable<TraktSyncWatchlistPostMovie> Movies { get; set; }

        /// <summary>
        /// An optional list of <see cref="TraktSyncWatchlistPostShow" />s.
        /// <para>Each <see cref="TraktSyncWatchlistPostShow" /> must have at least a valid Trakt id.</para>
        /// </summary>
        [JsonProperty(PropertyName = "shows")]
        public IEnumerable<TraktSyncWatchlistPostShow> Shows { get; set; }

        /// <summary>
        /// An optional list of <see cref="TraktSyncWatchlistPostEpisode" />s.
        /// <para>Each <see cref="TraktSyncWatchlistPostEpisode" /> must have at least a valid Trakt id.</para>
        /// </summary>
        [JsonProperty(PropertyName = "episodes")]
        public IEnumerable<TraktSyncWatchlistPostEpisode> Episodes { get; set; }

        /// <summary>Returns a new <see cref="TraktSyncWatchlistPostBuilder" /> instance.</summary>
        /// <returns>A new <see cref="TraktSyncWatchlistPostBuilder" /> instance.</returns>
        public static TraktSyncWatchlistPostBuilder Builder() => new TraktSyncWatchlistPostBuilder();
    }

    /// <summary>
    /// This is a helper class to build a <see cref="TraktSyncWatchlistPost" />.
    /// <para>
    /// It is recommended to use this class to build a watchlist post.<para /> 
    /// An instance of this class can be obtained with <see cref="TraktSyncWatchlistPost.Builder()" />.
    /// </para>
    /// </summary>
    public class TraktSyncWatchlistPostBuilder
    {
        private TraktSyncWatchlistPost _watchlistPost;

        /// <summary>Initializes a new instance of the <see cref="TraktSyncWatchlistPostBuilder" /> class.</summary>
        public TraktSyncWatchlistPostBuilder()
        {
            _watchlistPost = new TraktSyncWatchlistPost();
        }

        /// <summary>Adds a <see cref="TraktMovie" />, which will be added to the watchlist post.</summary>
        /// <param name="movie">The Trakt movie, which will be added.</param>
        /// <returns>The current <see cref="TraktSyncWatchlistPostBuilder" /> instance.</returns>
        /// <exception cref="ArgumentNullException">
        /// Thrown, if the given movie is null.
        /// Thrown, if the given movie ids are null.
        /// </exception>
        /// <exception cref="ArgumentException">
        /// Thrown, if the given movie has no valid ids set.
        /// Thrown, if the given movie has an year set, which has more or less than four digits.
        /// </exception>
        public TraktSyncWatchlistPostBuilder AddMovie(TraktMovie movie)
        {
            if (movie == null)
                throw new ArgumentNullException(nameof(movie));

            if (movie.Ids == null)
                throw new ArgumentNullException(nameof(movie.Ids));

            if (!movie.Ids.HasAnyId)
                throw new ArgumentException("no movie ids set or valid", nameof(movie.Ids));

            if (movie.Year.HasValue && movie.Year.Value.ToString().Length != 4)
                throw new ArgumentException("movie year not valid", nameof(movie.Year));

            EnsureMoviesListExists();

            var existingMovie = _watchlistPost.Movies.Where(m => m.Ids == movie.Ids).FirstOrDefault();

            if (existingMovie != null)
                return this;

            (_watchlistPost.Movies as List<TraktSyncWatchlistPostMovie>).Add(
                new TraktSyncWatchlistPostMovie
                {
                    Ids = movie.Ids,
                    Title = movie.Title,
                    Year = movie.Year
                });

            return this;
        }

        public TraktSyncWatchlistPostBuilder AddMovies(IEnumerable<TraktMovie> movies)
        {
            if (movies == null)
                throw new ArgumentNullException(nameof(movies));

            if (movies.Count() == 0)
                return this;

            foreach (var movie in movies)
                AddMovie(movie);

            return this;
        }

        /// <summary>Adds a <see cref="TraktShow" />, which will be added to the watchlist post.</summary>
        /// <param name="show">The Trakt show, which will be added.</param>
        /// <returns>The current <see cref="TraktSyncWatchlistPostBuilder" /> instance.</returns>
        /// <exception cref="ArgumentNullException">
        /// Thrown, if the given show is null.
        /// Thrown, if the given show ids are null.
        /// </exception>
        /// <exception cref="ArgumentException">
        /// Thrown, if the given show has no valid ids set.
        /// Thrown, if the given show has an year set, which has more or less than four digits.
        /// </exception>
        public TraktSyncWatchlistPostBuilder AddShow(TraktShow show)
        {
            ValidateShow(show);
{'fraction_non_alphanumeric': 0.11481140754369826, 'fraction_numerical': 0.00027598896044158235, 'mean_word_length': 2.193595769682726, 'pattern_counts': {'":': 0, '<': 133, '<?xml version=': 0, '>': 137, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1222419', 'n_tokens_mistral': 2987, 'n_tokens_neox': 2854, 'n_words': 850}