using Microsoft.EntityFrameworkCore;
using PARR.Domain.Entities.Base;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace PARR.Domain.Entities
{
    /// <summary>
    /// Наряды ЕСПП
    /// </summary>
    [Table("Orders")]
    [Index(nameof(Number), IsUnique = true)]
    public class Order : IBaseEntity
    {
        [Key]
        public Guid Id { get; set; }

        public DateTimeOffset DateCreated { get; set; }

        public DateTimeOffset? DateModified { get; set; }

        public required string Number { get; set; }

        public required string ShortName { get; set; }

        public string? WorkGroup { get; set; }

        public Guid? TemplateId { get; set; }

        /// <summary>
        /// Статус в ЕСПП
        /// </summary>
        public int StatusCode { get; set; }

        /// <summary>
        /// Статус который должен быть в ЕСПП
        /// </summary>
        public int? NextStatusCode { get; set; }

        /// <summary>
        /// Дата генерации наряда в ЕСПП
        /// </summary>
        public DateTimeOffset? GenerateDate { get; set; }

        public DateTimeOffset ExpirationDate { get; set; }

        [ForeignKey(nameof(TemplateId))]
        public Template? Template { get; set; }

        [ForeignKey(nameof(StatusCode))]
        public OrderStatus? OrderStatus { get; set; }

        [ForeignKey(nameof(NextStatusCode))]
        public OrderStatus? NextStatus { get; set; }

        public ICollection<AgentHistory> AgentHistories { get; set; } = new HashSet<AgentHistory>();
    }
}
