using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.IO;

namespace Rainbow.Models
{
    public class Project : IAuditInfo
    {
        public Project()
        {
            TimeSheetEntries = new List<TimeSheetEntry>();
            Tickets = new List<Ticket>();
        }

        [Key]
        public int Id { get; set; }

        [Required]
        public string Name { get; set; }

        [DisplayName("Aktiv")]
        public bool Active { get; set; }

        [Required, DisplayName("Verzeichnisname")]
        public string DirectoryName { get; set; }

        [DisplayName("Beschreibung")]
        public string Description { get; set; }

        [DisplayName("Pauschale Abrechnung")]
        public bool FlatRate { get; set; }

        [DisplayName("Deadline"), DataType(DataType.Date)]
        public DateTime? Deadline { get; set; }

        [Display(Name = "Vorausbezahlte Stunden")]
        public double PrepaidHours { get; set; }

        [Required, ForeignKey("Customer"), DisplayName("Kunde")]
        public int CustomerId { get; set; }
        [DisplayName("Kunde")]
        public virtual Customer Customer { 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; }

        public virtual ICollection<TimeSheetEntry> TimeSheetEntries { get; set; }

        public virtual ICollection<Ticket> Tickets { get; set; }

        public string GetProjectDirectoryUrl(string basePath)
        {
            return "file:///" + Path.Combine(basePath, Customer.DirectoryName, DirectoryName).Replace("\\", "/");
        }
    }
}
