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

namespace NewWebApi.Schema
{
    [GraphQLMetadata("Mutation")]
    public class Mutation
    {
        private Context context { get; set; }

        public Mutation()
        {
            context = new Context();
        }

        [GraphQLMetadata("addAuthor")]
        public List<Author> AddAuthor(int id, string firstName, string lastName)
        {
            context.Authors.Add(new Author
            {
                Id = id,
                FirstName = firstName,
                LastName = lastName
            });

            return context.Authors;
        }

        [GraphQLMetadata("addBook")]
        public List<Book> AddBook(int id, string title, string published)
        {
            context.Books.Add(new Book
            {
                Id = id,
                Title = title,
                Published = Convert.ToDateTime(published)
            });

            return context.Books;
        }
    }
}
