using System.Collections.ObjectModel;
using System.Linq;
using Valg.EVA.Skanning.Contracts.CommonEnums;
using Valg.EVA.Skanning.ServicesModel.Internal.SystemSettings;

namespace Valg.EVA.Skanning.Services.SystemSettings
{
    public class SystemSettingsService : ISystemSettingsService
    {
        private readonly ISystemSettingsProvider systemSettingsProvider;

        public SystemSettingsService(ISystemSettingsProvider systemSettingsProvider)
        {
            this.systemSettingsProvider = systemSettingsProvider;
        }

        public int GetDataRefreshInterval()
        {
            return systemSettingsProvider.GetDataRefreshInterval();
        }

        public void PreloadData()
        {
            systemSettingsProvider.PreloadData();
        }

        public int GetBarcodeShortBoroughLength()
        {
            return systemSettingsProvider.GetBarcodeShortBoroughLength();
        }

        public AdditionalElectionConfiguration GetAdditionalElectionConfiguration(string electionEventId, string electionId, string electionGroupId, string contestId)
        {
            return systemSettingsProvider.GetAdditionalElectionConfiguration(electionEventId, electionId, electionGroupId, contestId);
        }

        public ReadOnlyCollection<BallotPaperLayoutDescription> GetBallotPaperLayoutDescriptions()
        {
            return systemSettingsProvider.GetBallotPaperLayoutDescriptions();
        }

        public BallotPaperLayoutDescription GetBallotPaperLayoutDescription(BallotPaperType ballotPaperType)
        {
            var layoutDescription = systemSettingsProvider.GetBallotPaperLayoutDescriptions()
                   .SingleOrDefault(descr => descr.BallotPaperType == ballotPaperType);

            if (layoutDescription == null)
            {
                layoutDescription = BallotPaperLayoutDescription.Empty;
            }

            return layoutDescription;
        }

        public int GetTransferStatusCheckTimeoutInterval()
        {
            return systemSettingsProvider.GetTransferStatusCheckTimeoutInterval();
        }

        public int GetStampFillPercentageMinimum()
        {
            return systemSettingsProvider.GetStampFillPercentageMinimum();
        }

        public int GetBallotIdLength()
        {
            return systemSettingsProvider.GetBallotIdLength();
        }

        public int GetBallotNumberLength()
        {
            return systemSettingsProvider.GetBallotNumberLength();
        }
        
        public int GetBarcodeLongLength()
        {
            return systemSettingsProvider.GetBarcodeLongLength();
        }

        public int GetBarcodeShortLength()
        {
            return systemSettingsProvider.GetBarcodeShortLength();
        }

        public string GetOsloDistrictList()
        {
            return systemSettingsProvider.GetOsloDistrictList();
        }
    }
}
