﻿// Code generated by Microsoft (R) AutoRest Code Generator 0.9.7.0
// Changes may cause incorrect behavior and will be lost if the code is regenerated.

using System;
using System.Linq;
using Newtonsoft.Json.Linq;

namespace AzureBooks.Models
{
    public partial class Book
    {
        private int? _id;
        
        /// <summary>
        /// Optional.
        /// </summary>
        public int? Id
        {
            get { return this._id; }
            set { this._id = value; }
        }
        
        private string _publisher;
        
        /// <summary>
        /// Optional.
        /// </summary>
        public string Publisher
        {
            get { return this._publisher; }
            set { this._publisher = value; }
        }
        
        private string _title;
        
        /// <summary>
        /// Required.
        /// </summary>
        public string Title
        {
            get { return this._title; }
            set { this._title = value; }
        }
        
        /// <summary>
        /// Initializes a new instance of the Book class.
        /// </summary>
        public Book()
        {
        }
        
        /// <summary>
        /// Initializes a new instance of the Book class with required
        /// arguments.
        /// </summary>
        public Book(string title)
            : this()
        {
            if (title == null)
            {
                throw new ArgumentNullException("title");
            }
            this.Title = title;
        }
        
        /// <summary>
        /// Deserialize the object
        /// </summary>
        public virtual void DeserializeJson(JToken inputObject)
        {
            if (inputObject != null && inputObject.Type != JTokenType.Null)
            {
                JToken idValue = inputObject["Id"];
                if (idValue != null && idValue.Type != JTokenType.Null)
                {
                    this.Id = ((int)idValue);
                }
                JToken publisherValue = inputObject["Publisher"];
                if (publisherValue != null && publisherValue.Type != JTokenType.Null)
                {
                    this.Publisher = ((string)publisherValue);
                }
                JToken titleValue = inputObject["Title"];
                if (titleValue != null && titleValue.Type != JTokenType.Null)
                {
                    this.Title = ((string)titleValue);
                }
            }
        }
        
        /// <summary>
        /// Serialize the object
        /// </summary>
        /// <returns>
        /// Returns the json model for the type Book
        /// </returns>
        public virtual JToken SerializeJson(JToken outputObject)
        {
            if (outputObject == null)
            {
                outputObject = new JObject();
            }
            if (this.Title == null)
            {
                throw new ArgumentNullException("Title");
            }
            if (this.Id != null)
            {
                outputObject["Id"] = this.Id.Value;
            }
            if (this.Publisher != null)
            {
                outputObject["Publisher"] = this.Publisher;
            }
            if (this.Title != null)
            {
                outputObject["Title"] = this.Title;
            }
            return outputObject;
        }
    }
}
