using System.Collections.Generic;
using System.Linq;
using CounterDrone.Core.Models;
using SQLite;

namespace CounterDrone.Core.Repository
{
    public class ControlZoneRepository : BaseRepository<ControlZone>
    {
        public ControlZoneRepository(SQLiteConnection db) : base(db) { }

        public List<ControlZone> GetByScenarioId(string scenarioId)
        {
            return Db.Table<ControlZone>()
                     .Where(z => z.ScenarioId == scenarioId)
                     .OrderBy(z => z.OrderIndex)
                     .ToList();
        }

        public void DeleteByScenarioId(string scenarioId)
        {
            var zones = GetByScenarioId(scenarioId);
            foreach (var z in zones)
                Db.Delete(z);
        }
    }
}
