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

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

        public List<ScenarioUnit> GetByScenarioId(string scenarioId)
        {
            return Db.Table<ScenarioUnit>().Where(e => e.ScenarioId == scenarioId).ToList();
        }

        /// <summary>按任务和角色查询装备（EquipmentRole: 0=Detection, 1=LaunchPlatform）</summary>
        public List<ScenarioUnit> GetByScenarioIdAndRole(string scenarioId, int equipmentRole)
        {
            return Db.Table<ScenarioUnit>()
                .Where(e => e.ScenarioId == scenarioId && e.EquipmentRole == equipmentRole)
                .ToList();
        }

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