using System;
using System.Collections.Generic;

namespace XLAB
{
    public sealed class EkzDirectoryItem
    {
        public int Id { get; set; }

        public int TypeSizeId { get; set; }

        public string MeasurementAreaName { get; set; }

        public string InstrumentName { get; set; }

        public string TypeName { get; set; }

        public string RangeText { get; set; }

        public string AccuracyText { get; set; }

        public string RegistryNumber { get; set; }

        public int OwnerOrganizationId { get; set; }

        public string OwnerOrganizationName { get; set; }

        public string SerialNumber { get; set; }

        public string InventoryNumber { get; set; }

        public string Notes { get; set; }
    }

    public sealed class EkzMkDirectoryItem
    {
        public int CardId { get; set; }

        public int InstrumentId { get; set; }

        public string VerificationTypeName { get; set; }

        public string VerificationOrganizationName { get; set; }

        public string DocumentNumber { get; set; }

        public string VerificationDocumentNumber { get; set; }

        public DateTime? VerificationDocumentDate { get; set; }

        public int PeriodMonths { get; set; }

        public DateTime? AcceptedOn { get; set; }

        public DateTime? PlannedOn { get; set; }

        public DateTime? PerformedOn { get; set; }

        public DateTime? IssuedOn { get; set; }

        public bool? IsPassed { get; set; }

        public string Notes { get; set; }

        public string ResultText
        {
            get
            {
                if (!IsPassed.HasValue)
                {
                    return string.Empty;
                }

                return IsPassed.Value ? "Годен" : "Не годен";
            }
        }

        public string VerificationDocumentDisplay
        {
            get
            {
                if (string.IsNullOrWhiteSpace(VerificationDocumentNumber))
                {
                    return VerificationDocumentDate.HasValue ? VerificationDocumentDate.Value.ToString("d") : string.Empty;
                }

                if (!VerificationDocumentDate.HasValue)
                {
                    return VerificationDocumentNumber;
                }

                return string.Format("{0} от {1:d}", VerificationDocumentNumber, VerificationDocumentDate.Value);
            }
        }
    }

    internal sealed class EkzDeleteImpactItem
    {
        public string TableName { get; set; }

        public int RowCount { get; set; }
    }

    internal sealed class EkzDeletePreview
    {
        public bool CanDelete { get; set; }

        public IReadOnlyList<EkzDeleteImpactItem> ImpactItems { get; set; }

        public string ConfirmationMessage { get; set; }

        public string WarningMessage { get; set; }
    }

    internal sealed class EkzDeleteResult
    {
        public bool IsDeleted { get; set; }

        public IReadOnlyList<EkzDeleteImpactItem> ImpactItems { get; set; }

        public string WarningMessage { get; set; }
    }

    internal static class EkzDirectoryRules
    {
        public const int SerialNumberMaxLength = 30;

        public const int InventoryNumberMaxLength = 30;

        public const int NotesMaxLength = 8000;
    }
}
