// ------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//  
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
//     
//	   Copyright (c) 2018 Citrix ShareFile. All rights reserved.
// </auto-generated>
// ------------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Net;

using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using ShareFile.Api.Client.Extensions;
using ShareFile.Api.Client.Exceptions;

namespace ShareFile.Api.Client.Models 
{
	/// <summary>
	/// Represents an Asynchronous operation - any operation that is started but
	/// the results will take time to complete.
	/// </summary>
	public class AsyncOperation : ODataObject 
	{
		/// <summary>
		/// Operation type
		/// </summary>
		public SafeEnum<AsyncOperationType> Operation { get; set; }
		/// <summary>
		/// ShareFile Account
		/// </summary>
		public Account Account { get; set; }
		/// <summary>
		/// Represents the Zone that is driving the asynchronous operation process. It
		/// may be null if the operation is driven by the control plane.
		/// </summary>
		public Zone AuthorityZone { get; set; }
		/// <summary>
		/// Source Item for the operation.
		/// </summary>
		public Item Source { get; set; }
		/// <summary>
		/// User that initiated the operation
		/// </summary>
		public User User { get; set; }
		/// <summary>
		/// Operation creation date
		/// </summary>
		public DateTime? CreationDate { get; set; }
		/// <summary>
		/// Operation state. States 'Created' and 'Scheduled' indicate the operation is
		/// in progress; States 'Success' and 'Failure' indicate the operatoin is finalized
		/// </summary>
		public SafeEnum<AsyncOperationState> State { get; set; }
		/// <summary>
		/// Last time the operation state was modified
		/// </summary>
		public DateTime? UpdateDate { get; set; }
		/// <summary>
		/// Target Item for the operation.
		/// </summary>
		public Item Target { get; set; }
		/// <summary>
		/// Batch Identifier for an asynchronous operation that includes multiple Items - for
		/// example, a recursive Copy will create a single AsyncOp instance per file, all sharing
		/// the same BatchID
		/// </summary>
		public string BatchID { get; set; }
		/// <summary>
		/// Item ID used as source for the Batch operation
		/// </summary>
		public string BatchSourceID { get; set; }
		/// <summary>
		/// Item ID used as target for the Batch operation
		/// </summary>
		public string BatchTargetID { get; set; }
		/// <summary>
		/// BatchProgress indicates the progress of the Batch operation
		/// </summary>
		public double? BatchProgress { get; set; }
		/// <summary>
		/// Batch Operation state. State 'Scheduled' indicate the operation is
		/// in progress; States 'Success' and 'Failure' indicate the operation is finalized
		/// </summary>
		public SafeEnum<AsyncOperationState> BatchState { get; set; }
		public int? BatchTotal { get; set; }

		public override void Copy(ODataObject source, JsonSerializer serializer)
		{
			if(source == null || serializer == null) return;
			base.Copy(source, serializer);

			var typedSource = source as AsyncOperation;
			if(typedSource != null)
			{
				Operation = typedSource.Operation;
				Account = typedSource.Account;
				AuthorityZone = typedSource.AuthorityZone;
				Source = typedSource.Source;
				User = typedSource.User;
				CreationDate = typedSource.CreationDate;
				State = typedSource.State;
				UpdateDate = typedSource.UpdateDate;
				Target = typedSource.Target;
				BatchID = typedSource.BatchID;
				BatchSourceID = typedSource.BatchSourceID;
				BatchTargetID = typedSource.BatchTargetID;
				BatchProgress = typedSource.BatchProgress;
				BatchState = typedSource.BatchState;
				BatchTotal = typedSource.BatchTotal;
			}
			else
			{
				JToken token;
				if(source.TryGetProperty("Operation", out token) && token.Type != JTokenType.Null)
				{
					Operation = (SafeEnum<AsyncOperationType>)serializer.Deserialize(token.CreateReader(), typeof(SafeEnum<AsyncOperationType>));
				}
				if(source.TryGetProperty("Account", out token) && token.Type != JTokenType.Null)
				{
					Account = (Account)serializer.Deserialize(token.CreateReader(), typeof(Account));
				}
				if(source.TryGetProperty("AuthorityZone", out token) && token.Type != JTokenType.Null)
				{
					AuthorityZone = (Zone)serializer.Deserialize(token.CreateReader(), typeof(Zone));
				}
				if(source.TryGetProperty("Source", out token) && token.Type != JTokenType.Null)
				{
					Source = (Item)serializer.Deserialize(token.CreateReader(), typeof(Item));
				}
				if(source.TryGetProperty("User", out token) && token.Type != JTokenType.Null)
				{
					User = (User)serializer.Deserialize(token.CreateReader(), typeof(User));
				}
				if(source.TryGetProperty("CreationDate", out token) && token.Type != JTokenType.Null)
				{
					CreationDate = (DateTime?)serializer.Deserialize(token.CreateReader(), typeof(DateTime?));
				}
				if(source.TryGetProperty("State", out token) && token.Type != JTokenType.Null)
				{
					State = (SafeEnum<AsyncOperationState>)serializer.Deserialize(token.CreateReader(), typeof(SafeEnum<AsyncOperationState>));
				}
				if(source.TryGetProperty("UpdateDate", out token) && token.Type != JTokenType.Null)
				{
					UpdateDate = (DateTime?)serializer.Deserialize(token.CreateReader(), typeof(DateTime?));
				}
				if(source.TryGetProperty("Target", out token) && token.Type != JTokenType.Null)
				{
					Target = (Item)serializer.Deserialize(token.CreateReader(), typeof(Item));
				}
				if(source.TryGetProperty("BatchID", out token) && token.Type != JTokenType.Null)
				{
					BatchID = (string)serializer.Deserialize(token.CreateReader(), typeof(string));
				}
				if(source.TryGetProperty("BatchSourceID", out token) && token.Type != JTokenType.Null)
				{
					BatchSourceID = (string)serializer.Deserialize(token.CreateReader(), typeof(string));
				}
				if(source.TryGetProperty("BatchTargetID", out token) && token.Type != JTokenType.Null)
				{
					BatchTargetID = (string)serializer.Deserialize(token.CreateReader(), typeof(string));
				}
				if(source.TryGetProperty("BatchProgress", out token) && token.Type != JTokenType.Null)
				{
					BatchProgress = (double?)serializer.Deserialize(token.CreateReader(), typeof(double?));
				}
				if(source.TryGetProperty("BatchState", out token) && token.Type != JTokenType.Null)
				{
					BatchState = (SafeEnum<AsyncOperationState>)serializer.Deserialize(token.CreateReader(), typeof(SafeEnum<AsyncOperationState>));
				}
				if(source.TryGetProperty("BatchTotal", out token) && token.Type != JTokenType.Null)
				{
					BatchTotal = (int?)serializer.Deserialize(token.CreateReader(), typeof(int?));
				}
			}
		}
	}
}