using Valg.EVA.Skanning.Entity.ReadModel;
using Valg.EVA.Skanning.Entity.SqlConnection;

namespace Valg.EVA.Skanning.Repositories.ElectionConfig
{
    public class ElectionConfigMetadataRepository : IElectionConfigMetadataRepository
    {
        private readonly ISqlConnectionFactory factory;

        public ElectionConfigMetadataRepository(ISqlConnectionFactory factory)
        {
            this.factory = factory;
        }

        public ElectionConfigShortMetadataInfo GetLatestElectionConfigMetadataInfo(string electionEventId)
        {
            return factory.SP_Execute<ElectionConfigShortMetadataInfo>("ElectionConfig_GetElectionConfig", new { ElectionEventId = electionEventId });
        }

        public long GetLastImportedConfigId()
        {
            var result = factory.SP_Get("ElectionConfig_GetLastImportedConfigId");
            return (result == null)
                ? -1
                : result.Id;
        }
    }
}
