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> GetByScenarioId(string scenarioId)
        {
            return Db.Table<Waypoint>()
                     .Where(w => w.ScenarioId == scenarioId)
                     .OrderBy(w => w.OrderIndex)
                     .ToList();
        }

        public List<Waypoint> GetByScenarioAndWave(string scenarioId, string waveId)
        {
            return Db.Table<Waypoint>()
                     .Where(w => w.ScenarioId == scenarioId && w.WaveId == waveId)
                     .OrderBy(w => w.OrderIndex)
                     .ToList();
        }

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