﻿using System;

namespace PiggyWebAPI.models
{
    public class PiggyAccountHistory
    {
        private string _action;

        public PiggyAccountHistory(string action, decimal amount)
        {
            Action = action;
            Date = DateTime.UtcNow;
            Amount = amount;
        }

        /// <summary>
        ///     The id
        /// </summary>
        public int Id { get; set; }

        /// <summary>
        ///     The action. Withdraw or Insert
        /// </summary>
        public string Action
        {
            get => _action ?? (_action = "");
            private set
            {
                if (value.Equals("withdraw", StringComparison.CurrentCultureIgnoreCase) ||
                    value.Equals("deposit", StringComparison.CurrentCultureIgnoreCase))
                    _action = value;
                else
                    throw new ArgumentException("Unable to set action. Must be 'withdraw' or 'deposit'");
            }
        }

        /// <summary>
        ///     The date and time of the history action
        /// </summary>
        public DateTime Date { get; set; }

        /// <summary>
        ///     The amount of the change
        /// </summary>
        public decimal Amount { get; set; }
    }
}