using System;

namespace XLAB
{
    public sealed class PlanningItem
    {
        public int InstrumentId { get; set; }

        public int TypeSizeId { get; set; }

        public int OwnerOrganizationId { get; set; }

        public string OwnerOrganizationName { get; set; }

        public string MeasurementAreaName { get; set; }

        public string InstrumentName { get; set; }

        public string TypeName { get; set; }

        public string RangeText { get; set; }

        public string RegistryNumber { get; set; }

        public string SerialNumber { get; set; }

        public string InventoryNumber { get; set; }

        public int? PlanId { get; set; }

        public int? EffectiveTemplateId { get; set; }

        public int? PeriodMonths { get; set; }

        public DateTime? LastVerificationOn { get; set; }

        public DateTime? PlannedOn { get; set; }

        public bool IsExplicitPlan { get; set; }

        public string PlanSource { get; set; }

        public string PeriodSource { get; set; }

        public bool CanPersistPlan
        {
            get { return PlanId.HasValue || EffectiveTemplateId.HasValue; }
        }

        public string PeriodDisplay
        {
            get { return PeriodMonths.HasValue ? string.Format("{0} мес.", PeriodMonths.Value) : string.Empty; }
        }

        public string RecordKindText
        {
            get { return IsExplicitPlan ? "EKZMCP" : "Расчет"; }
        }

        public string PersistenceText
        {
            get { return CanPersistPlan ? string.Empty : "Только расчет"; }
        }
    }

    internal sealed class PlanningInstrumentOption
    {
        public int Id { get; set; }

        public int TypeSizeId { get; set; }

        public int OwnerOrganizationId { get; set; }

        public string DisplayName { get; set; }

        public override string ToString()
        {
            return DisplayName ?? string.Empty;
        }
    }

    internal sealed class PlanningTemplateOption
    {
        public int Id { get; set; }

        public int TypeSizeId { get; set; }

        public int? CycleId { get; set; }

        public string CycleName { get; set; }

        public int? GroupId { get; set; }

        public string GroupName { get; set; }

        public int PeriodMonths { get; set; }

        public string Comment { get; set; }

        public string DisplayName
        {
            get
            {
                var parts = new System.Collections.Generic.List<string>
                {
                    string.Format("{0} мес.", PeriodMonths)
                };

                if (!string.IsNullOrWhiteSpace(CycleName))
                {
                    parts.Add(CycleName.Trim());
                }

                if (!string.IsNullOrWhiteSpace(GroupName))
                {
                    parts.Add(GroupName.Trim());
                }

                if (!string.IsNullOrWhiteSpace(Comment))
                {
                    parts.Add(Comment.Trim());
                }

                return string.Join(" / ", parts.ToArray());
            }
        }

        public override string ToString()
        {
            return DisplayName;
        }
    }

    internal sealed class PlanningEditSeed
    {
        public int TargetYear { get; set; }

        public int? PlanId { get; set; }

        public int InstrumentId { get; set; }

        public int? TemplateId { get; set; }

        public DateTime? PlannedOn { get; set; }
    }

    internal sealed class PlanningEditResult
    {
        public int? PlanId { get; set; }

        public int InstrumentId { get; set; }

        public int TemplateId { get; set; }

        public DateTime PlannedOn { get; set; }
    }
}
