using BHServer.Data;
using BHServer.Models;
using Microsoft.AspNetCore.Mvc;
using System;

namespace BHServer.Controllers
{
    public class AssaultTroopController : Controller
    {
        private readonly ApplicationDbContext _db;
        public AssaultTroopController(ApplicationDbContext db)
        {
            _db = db;
        }
        public IActionResult Index()
        {
            List<AssaultTroop> ObjectAssaultTroopList = _db.AssaultTroops.ToList();
            // If the above line faulters then ensure SQL Server is running
            return View(ObjectAssaultTroopList);
        }

        [HttpGet]
        public IEnumerable<String> Get()
        {
            List<String> arr = [];
            foreach (var entry in _db.AssaultTroops.ToList())
            {
                String str = @"{""id"": " + entry.Id + @", ""name"": """ + entry.Name + @""", ""faction"": " + entry.Faction + @", ""type"": " + entry.Type + @", ""province"": " + entry.Province + @", ""orders"": " + entry.Orders + @", ""owner"": " + entry.Owner + "}";
                arr.Add(str);
            }
            return arr;
        }

        // GET /<APIController>/5
        [HttpGet("{id}")]
        public String Get(int id)
        {
            var entry = _db.AssaultTroops.ElementAt(id);
            String str = @"{""id"": " + entry.Id + @", ""name"": """ + entry.Name + @""", ""faction"": " + entry.Faction + @", ""type"": " + entry.Type + @", ""province"": " + entry.Province + @", ""orders"": " + entry.Orders + @", ""owner"": " + entry.Owner + "}";
            return str;
        }

        // POST /<APIController>
        [HttpPost]
        public void Post([FromBody] string value)
        {
            // TODO: Implement
        }

        // PUT /<APIController>/5
        [HttpPut("{id}")]
        public void Put(int id, [FromBody] string value)
        {
            // TODO: Implement
        }

        // DELETE /<APIController>/5
        [HttpDelete("{id}")]
        public void Delete(int id)
        {
            // TODO: Implement
        }
    }
}
