using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace Hcs.WebApp.Data.Hcs
{
    public class Operation
    {
        public enum OperationType
        {
            [Display(Description = "Экспорт общего справочника")]
            NsiCommon_ExportNsiItem_15_7_0_1,

            [Display(Description = "Экспорт частного справочника")]
            Nsi_ExportNsiItem_15_7_0_1,

            [Display(Description = "Парсинг данных домов")]
            ParseHousesData_15_7_0_1
        }

        public enum OperationKind
        {
            Remote,
            Parse
        }

        public int Id { get; set; }

        public int CampaignId { get; set; }

        public virtual Campaign Campaign { get; set; } = null!;

        public OperationType Type { get; set; }

        public DateTime CreatedAt { get; set; }

        public DateTime? StartedAt { get; set; }

        public DateTime? EndedAt { get; set; }

        public string? MessageGuid { get; set; }

        public string? FailureReason { get; set; }

        public virtual ICollection<Registry> Registries { get; set; } = [];

        public virtual ICollection<House> Houses { get; set; } = [];

        [NotMapped]
        public bool Completed => EndedAt.HasValue;

        [NotMapped]
        public OperationKind Kind => Type switch
        {
            OperationType.NsiCommon_ExportNsiItem_15_7_0_1 or
            OperationType.Nsi_ExportNsiItem_15_7_0_1 => OperationKind.Remote,

            OperationType.ParseHousesData_15_7_0_1 => OperationKind.Parse
        };
    }
}
