using System;
using System.Runtime.Serialization;

namespace BS.Shared.DataContracts
{
    [DataContract]
    public class CostRatePeriodDC : IDataContract
    {
        [DataMember]
        public long? CostRatePeriodOid { get; set; }

        [DataMember]
        public long? CostRatePeriodVersion { get; set; }

        [DataMember]
        public CostRatePeriodType CostRateType { get; set; }

        [DataMember]
        public decimal? CostRateValue { get; set; }

        [DataMember]
        public DateTime? EndDate { get; set; }

        [DataMember]
        public string Notice { get; set; }

        [DataMember]
        public DateTime? StartDate { get; set; }

        [DataMember]
        public string UnitName { get; set; }

        [DataMember]
        public ValueListEntryDC ValueListEntry { get; set; }

        public virtual decimal? GetBEInHours(decimal? be)
        {
            decimal? crv = this.CostRateValue;
            if (!crv.HasValue)
                crv = 60;
            return (be * crv.Value) / 60m;
        }

        public virtual decimal GetBEInHours(decimal be)
        {
            decimal? crv = this.CostRateValue;
            if (!crv.HasValue)
                crv = 60;
            return (be * crv.Value) / 60m;
        }

        public virtual decimal? GetBEInMinutes(decimal? be)
        {
            decimal? crv = this.CostRateValue;
            if (!crv.HasValue)
                crv = 60;
            return be * crv.Value;
            
        }

        public virtual decimal GetBEInMinutes(decimal be)
        {
            decimal? crv = this.CostRateValue;
            if (!crv.HasValue)
                crv = 60;
            return be * crv.Value;
        }

        public virtual decimal? GetHoursInBE(decimal? hours)
        {
            decimal? crv = this.CostRateValue;
            if (!crv.HasValue)
                crv = 60;
            return (hours * 60m) / crv.Value;
                
        }

        public virtual decimal GetHoursInBE(decimal hours)
        {
            decimal? crv = this.CostRateValue;
            if (!crv.HasValue || crv.Value == 0)
                crv = 60;
            return (hours * 60m) / crv.Value;
        }

        public virtual decimal? GetMinutesInBE(decimal? minutes)
        {
            decimal? crv = this.CostRateValue;
            if (!crv.HasValue)
                crv = 60;
            return minutes / crv.Value;
                
        }

        public virtual decimal GetMinutesInBE(decimal minutes)
        {
            decimal? crv = this.CostRateValue;
            if (!crv.HasValue)
                crv = 60;
            return minutes / crv.Value;
        }
    }
}