using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace NewWebApi.Schema
{
    public class Context
    {

        public readonly List<Author> Authors = new List<Author>();
        public readonly List<Book> Books = new List<Book>();

        public Context()
        {

            Authors.Add(new Author { Id = 1, FirstName = "Ernest", LastName = "Hemingway"});
            Authors.Add(new Author { Id = 2, FirstName = "Charles", LastName = "Dickens" });

            Books.Add(new Book { Id = 1, Title = "The Old Man and the Sea", Published = Convert.ToDateTime("1952-01-11"), Author = Authors.Where(x => x.Id == 1).FirstOrDefault() });
            Books.Add(new Book { Id = 2, Title = "In Our Time", Published = Convert.ToDateTime("1924-01-01"), Author = Authors.Where(x => x.Id == 1).FirstOrDefault() });
            Books.Add(new Book { Id = 3, Title = "Oliver Twist", Published = Convert.ToDateTime("1837-01-01"), Author = Authors.Where(x => x.Id == 2).FirstOrDefault() });
            Books.Add(new Book { Id = 4, Title = "David Copperfield", Published = Convert.ToDateTime("1850-01-01"), Author = Authors.Where(x => x.Id == 2).FirstOrDefault() });

            Authors.Where(x=>x.Id == 1).FirstOrDefault().Books = Books.Where(x => x.Author.Id == 1).ToList();
            Authors.Where(x => x.Id == 2).FirstOrDefault().Books = Books.Where(x => x.Author.Id == 2).ToList();
        }
    }
}