using System;
using System.ComponentModel.DataAnnotations;

namespace Rainbow.Models
{
    public class TimeSheetEntry : IAuditInfo
    {
        public int Id { get; set; }

        [Display(Name = "Projekt")]
        public int ProjectId { get; set; }
        public virtual Project Project { get; set; }

        [Required, Display(Name = "Benutzer")]
        public int UserId { get; set; }
        public virtual ApplicationUser User { get; set; }

        [Display(Name = "Beschreibung")]
        public string Description { get; set; }

        [Display(Name = "Startzeit")]
        [DataType(DataType.DateTime)]
        public DateTime? StartTime { get; set; }

        [Display(Name = "Endzeit")]
        [DataType(DataType.DateTime)]
        public DateTime? EndTime { get; set; }

        [Display(Name = "Interne Bemerkungen")]
        public string InternalComments { get; set; }

        [Display(Name = "Stundensatz")]
        public decimal? HourlyRate { get; set; }

        [Display(Name = "Nicht verrechenbar")]
        public bool NotClearable { get; set; }

        [Required, Display(Name = "Erstellt")]
        public DateTime Created { get; set; }

        [Display(Name = "Erstellt von")]
        public string CreatedBy { get; set; }

        [Required, Display(Name = "Geändert")]
        public DateTime LastModified { get; set; }

        [Display(Name = "Geändert von")]
        public string LastModifiedBy { get; set; }

        [Display(Name = "Dauer")]
        public TimeSpan Duration
        {
            get
            {
                if (StartTime.HasValue && EndTime.HasValue)
                {
                    return EndTime.Value - StartTime.Value;
                }
                return TimeSpan.Zero;
            }
        }

        public string UserName
        {
            get { return User == null ? "-" : User.UserName; }
        }
    }
}
