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

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

        public List<Waypoint> GetByTaskId(string taskId)
        {
            return Db.Table<Waypoint>()
                     .Where(w => w.TaskId == taskId)
                     .OrderBy(w => w.OrderIndex)
                     .ToList();
        }

        public List<Waypoint> GetByTaskAndGroup(string taskId, string groupId)
        {
            return Db.Table<Waypoint>()
                     .Where(w => w.TaskId == taskId && w.GroupId == groupId)
                     .OrderBy(w => w.OrderIndex)
                     .ToList();
        }

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