using System;
using System.Collections.Generic;

namespace CareFusion.Mosaic.Interfaces.Types.Input
{
    /// <summary>
    /// Class which represents a stock delivery for a storage system.
    /// </summary>
    public class StockDelivery
    {
        #region Members

        /// <summary>
        /// Flag whether to lazy load dependencies.
        /// </summary>
        private bool _requireLazyLoad = false;

        /// <summary>
        /// Holds the list of order items which are assigned to this stock delivery.
        /// </summary>
        private List<StockDeliveryItem> _orderItems = new List<StockDeliveryItem>();

        #endregion

        #region Properties

        /// <summary>
        /// Gets or sets the identifier of the stock delivery.
        /// </summary>
        public int ID { get; set; }

        /// <summary>
        /// Gets or sets the identifier of the component which initiated this stock delivery.
        /// </summary>
        public int SourceID { get; set; }

        /// <summary>
        /// Gets or sets the delivery number.
        /// </summary>
        public string DeliveryNumber { get; set; }

        /// <summary>
        /// Gets or sets the optional box number according to this order.
        /// </summary>
        public string BoxNumber { get; set; }

        /// <summary>
        /// Gets or sets the priority of this stock output order.
        /// </summary>
        public StockDeliveryPriority Priority { get; set; }

        /// <summary>
        /// Gets or sets the state of the stock delivery.
        /// </summary>
        public StockDeliveryState State { get; set; }

        /// <summary>
        /// Gets or sets the created date of the stock delivery.
        /// </summary>
        public DateTime Created { get; set; }

        /// <summary>
        /// Gets or sets the tenant identifier of the stock delivery.
        /// </summary>
        public string TenantID { get; set; }

        /// <summary>
        /// Gets or sets the history date of the stock delivery.
        /// </summary>
        public DateTime HistoryDate { get; set; }

        /// <summary>
        /// Gets the list of items which are assigned to this stock output order.
        /// </summary>
        public List<StockDeliveryItem> Items { get => _orderItems; }

        /// <summary>
        /// Gets an array of the property names of this object.
        /// These names are required to serialize this object to the database.
        /// </summary>
        public string[] PropertyNames
        {
            get
            {
                return new string[] 
                {
                    "ID", "SourceID", "DeliveryNumber", 
                    "BoxNumber", "Priority",
                    "State", "Created", "TenantID"
                };
            }
        }

        /// <summary>
        /// Gets an array of the raw property values of this object.
        /// These values are required to serialize this object to the database.
        /// </summary>
        public object[] PropertyValues
        {
            get
            {
                return new object[] 
                {
                    this.ID,
                    this.SourceID,
                    this.DeliveryNumber,
                    this.BoxNumber,
                    this.Priority.ToString(),
                    this.State.ToString(),
                    this.Created,
                    this.TenantID
                };
            }
        }

        /// <summary>
        /// Gets an array of the property names which define the unique key of this object.
        /// These names are required to delete this object from the database.
        /// </summary>
        public string[] KeyPropertyNames
        {
            get
            {
                return new string[] { "ID", "TenantID" };
            }
        }

        #endregion

        /// <summary>
        /// Initializes a new instance of the <see cref="StockDelivery"/> class.
        /// </summary>
        public StockDelivery()
        {
            this.DeliveryNumber = string.Empty;
            this.BoxNumber = string.Empty;
            this.Created = DateTime.UtcNow;
            this.Priority = StockDeliveryPriority.Normal;
            this.State = StockDeliveryState.Queued;
            this.TenantID = string.Empty;
        }
    }
}
