using Valg.EVA.Skanning.Repositories.ElectionConfig;
using Valg.EVA.Skanning.ServicesModel.ElectionConfig.Model;

namespace Valg.EVA.Skanning.ServicesModel.ElectionConfig.DataProvider
{
    public class ElectionConfigMetadataProvider : IElectionConfigMetadataProvider
    {
        private readonly IElectionConfigMetadataRepository repository;

        public ElectionConfigMetadataProvider(IElectionConfigMetadataRepository repository)
        {
            this.repository = repository;
        }

        public ElectionConfigMetadata GetLatestElectionConfigMetadataInfo(string electionEventId)
        {
            var metadata = repository.GetLatestElectionConfigMetadataInfo(electionEventId);
            if (metadata != null)
            {
                return new ElectionConfigMetadata(metadata.Version, metadata.Created, metadata.MetadataTimestamp);
            }

            return null;
        }

        public long GetLastImportedConfigId()
        {
            return repository.GetLastImportedConfigId();
        }
    }
}
