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> GetByTaskId(string taskId)
        {
            return Db.Table<ControlZone>()
                     .Where(z => z.TaskId == taskId)
                     .OrderBy(z => z.OrderIndex)
                     .ToList();
        }

        public void DeleteByTaskId(string taskId)
        {
            var zones = GetByTaskId(taskId);
            foreach (var z in zones)
                Db.Delete(z);
        }
    }
}
