namespace ServiceCenter.Data.BLT
{
    using System;
    using System.ComponentModel;
    using DataAnnotations = System.ComponentModel.DataAnnotations;

    using BLToolkit.Common;
    using BLToolkit.DataAccess;
    using BLToolkit.Mapping;

    /// <summary>
    /// Заявка
    /// </summary>
    [TableName("Request")]
    public class Request : EntityBase
    {
        /// <summary>
        /// Пустой конструктор для BLToolkit
        /// </summary>
        public Request()
        {

        }

        public Request(Request request)
        {
            this.Id = request.Id;
            this.EmployeeId = request.EmployeeId;
            this.DateIn = request.DateIn;
            this.DateOut = request.DateOut;
            this.DeviceTypeId = request.DeviceTypeId;
            this.ManufacturerId = request.ManufacturerId;
            this.Model = request.Model;
            this.Description = request.Description;
            this.ClientName = request.ClientName;
            this.ClientPhone = request.ClientPhone;
            this.Cost = request.Cost;
            this.StatusId = request.StatusId;
            this.Comment = request.Comment;
        }

        [MapField("RequestId"), PrimaryKey, Identity, NonUpdatable, DisplayName("Id")]
        public int Id { get; set; }

        /// <summary>
        /// Ответственный/исполнитель
        /// </summary>
        [MapField("EmployeeId"), NotNull, DisplayName("Ответственный/исполнитель")]
        public int EmployeeId { get; set; }

        /// <summary>
        /// Ответственный/исполнитель
        /// </summary>
        [Association(CanBeNull = false, ThisKey = "EmployeeId", OtherKey = "Id"), DisplayName("Ответственный/исполнитель")]
        public Employee Employee { get; set; }

        /// <summary>
        /// Статус заявки
        /// </summary>
        [MapField("StatusId"), NotNull, DisplayName("Статус заявки")]
        public int StatusId { get; set; }

        /// <summary>
        /// Статус заявки
        /// </summary>
        [Association(CanBeNull = false, ThisKey = "StatusId", OtherKey = "Id"), DisplayName("Статус заявки")]
        public Status Status { get; set; }

        /// <summary>
        /// Дата приёма
        /// </summary>
        [NotNull, DisplayName("Дата приёма"), DataAnnotations.DataType(DataAnnotations.DataType.Date)]
        public DateTime DateIn { get; set; }

        /// <summary>
        /// Дата выдачи
        /// </summary>
        [NullDateTime, DisplayName("Дата выдачи"), DataAnnotations.DataType(DataAnnotations.DataType.Date)]
        public DateTime? DateOut { get; set; }

        /// <summary>
        /// Производитель
        /// </summary>
        [MapField("ManufacturerId"), NotNull, DisplayName("Производитель")]
        public int ManufacturerId { get; set; }

        /// <summary>
        /// Производитель
        /// </summary>
        [Association(CanBeNull = false, ThisKey = "ManufacturerId", OtherKey = "Id"), DisplayName("Производитель")]
        public Manufacturer Manufacturer { get; set; }

        /// <summary>
        /// Тип устройства
        /// </summary>
        [MapField("DeviceTypeId"), NotNull, DisplayName("Тип устройства")]
        public int DeviceTypeId { get; set; }

        /// <summary>
        /// Тип устройства
        /// </summary>
        [Association(CanBeNull = false, ThisKey = "DeviceTypeId", OtherKey = "Id"), DisplayName("Тип устройства")]
        public DeviceType DeviceType { get; set; }

        /// <summary>
        /// Модель
        /// </summary>
        [NotNull, DisplayName("Модель")]
        public string Model { get; set; }

        /// <summary>
        /// Описание неисправности
        /// </summary>
        [NotNull, DisplayName("Описание неисправности"), DataAnnotations.DataType(DataAnnotations.DataType.MultilineText), DataAnnotations.StringLength(250, ErrorMessage = "Максимум 250 символов")]
        public string Description { get; set; }

        /// <summary>
        /// Ф.И.О. клиента
        /// </summary>
        [NotNull, DisplayName("Ф.И.О. клиента"), DataAnnotations.DataType(DataAnnotations.DataType.Text), DataAnnotations.StringLength(150, ErrorMessage = "Максимум 150 символов")]
        public string ClientName { get; set; }

        /// <summary>
        /// Телефон клиента
        /// </summary>
        [Nullable, DisplayName("Телефон клиента"), DataAnnotations.DataType(DataAnnotations.DataType.Text), DataAnnotations.StringLength(50, ErrorMessage = "Максимум 50 символов")]
        public string ClientPhone { get; set; }

        /// <summary>
        /// Стоимость ремонта
        /// </summary>
        [NotNull, DisplayName("Стоимость ремонта"), DataAnnotations.Range(0, 10000, ErrorMessage = "Введите значение от 0 до 10000")]
        public int Cost { get; set; }

        /// <summary>
        /// Комметарий исполнителя
        /// </summary>
        [Nullable, DisplayName("Комметарий исполнителя"), DataAnnotations.DataType(DataAnnotations.DataType.MultilineText), DataAnnotations.StringLength(250, ErrorMessage = "Максимум 250 символов")]
        public string Comment { get; set; }
    }
}