using System.Collections.Generic;
using Valg.EVA.Skanning.Entity.ReadModel;
using Valg.EVA.Skanning.Entity.SqlConnection;

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

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

        public IEnumerable<XmlResult> GetContestByAreaContextId(string electionEventId, string areaContextId)
        {
            return factory.SP_GetList<XmlResult>("ElectionConfig_GetContestByAreaContextId", new { ElectionEventId = electionEventId, AreaContextId = areaContextId });
        }

        public IEnumerable<XmlResult> GetVotingCategoriesInContest(string electionEventId, string contestId)
        {
            return factory.SP_GetList<XmlResult>("ElectionConfig_GetVotingCategoryListInContest", new { ElectionEventId = electionEventId, ContestId = contestId });
        }

        public IEnumerable<XmlResult> GetElectionByContestId(string electionEventId, string contestId)
        {
            return factory.SP_GetList<XmlResult>("ElectionConfig_GetElectionByContestId", new { ElectionEventId = electionEventId, ContestId = contestId });
        }
        
        public IEnumerable<XmlResult> GetElectionEvents(string electionEventId)
        {
            return factory.SP_GetList<XmlResult>("ElectionConfig_GetElectionEventList", new { ElectionEventId = electionEventId });
        }

        public IEnumerable<XmlResult> GetContests(string electionEventId)
        {
            return factory.SP_GetList<XmlResult>("ElectionConfig_GetContestList", new { ElectionEventId = electionEventId });
        }

        public IEnumerable<XmlResult> GetElections(string electionEventId)
        {
            return factory.SP_GetList<XmlResult>("ElectionConfig_GetElectionList", new { ElectionEventId = electionEventId });
        }

        public IEnumerable<XmlResult> GetVotingCategories(string electionEventId)
        {
            return factory.SP_GetList<XmlResult>("ElectionConfig_GetVotingCategoryList", new { ElectionEventId = electionEventId });
        }

        public IEnumerable<XmlResult> GetReportingUnits(string electionEventId)
        {
            return factory.SP_GetList<XmlResult>("ElectionConfig_GetReportingUnitList", new { ElectionEventId = electionEventId });
        }
       
        public IEnumerable<XmlResult> GetCountMetricsForContest(string electionEventId, string contestId)
        {
            return factory.SP_GetList<XmlResult>("ElectionConfig_GetCountMetricsForContest", new { ElectionEventId = electionEventId, ContestId = contestId });
        }

        public XmlResult GetMaxWriteInForContest(string electionEventId, string contestId)
        {
            return factory.SP_Get<XmlResult>("ElectionConfig_GetMaxWriteInForContest", new { ElectionEventId = electionEventId, ContestId = contestId });
        }

        public IEnumerable<long> GetAllElectionEventIds()
        {
            return factory.SP_GetList<long>("ElectionConfig_GetAllElectionEventIds");
        }
    }
}
