using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Text;
using Entidades;

namespace AlquilaFacil.Controllers;

[Route("api/inquilino")]
[ApiController]
public class InquilinoController: ControllerBase
{
    public List<Entidades.Inquilino> inquilinos = new List<Entidades.Inquilino>{
    };
    [HttpGet]
    public IActionResult Get(){
        
        var htmlbuild = new StringBuilder();
        foreach (var inquilino in inquilinos)
        {
            htmlbuild.AppendFormat("<tr><td>{0}</td><td>{1}</td><td>{2}</td><td>{3}</td></tr>",
                                    inquilino.Dni, inquilino.Nombre, inquilino.Apellido, inquilino.Domicilio);
        }
        return Content(htmlbuild.ToString(), "text/html");
    }

    [HttpPost]
    public IActionResult Post([FromForm] Inquilino inq){
        if (inq == null) return BadRequest("Inquilino inválido.");
        if (inq.Dni == 0 ) return BadRequest("No se especifico dni");
        if (inq.Dni < 0 ) return BadRequest("Dni Invalido");



        return Content($"<p>Inquilino {inq.Nombre} agregado exitosamente.</p>", "text/html");
    }
}