using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ProjetDotNet.metier;
using ProjetDotNet.web;
using Newtonsoft.Json;


namespace ProjetDotNet.DAO
{
    public class DAORectangle:IDAO<Rect>
    {
        /*public Rect charge(int id)
        {
            RequeteHTTP httpRequest = new RequeteHTTP("http://127.0.0.1/test/chargerRect.php", id.ToString());

            string json = httpRequest.LancerHTTPRequest();
            
            Rect RectTest = JsonConvert.DeserializeObject<Rect>(json);
            return RectTest;
            
        }*/
        public Rect charge(int id, string nomFigure)
        {
            RequeteHTTP httpRequest = new RequeteHTTP("http://127.0.0.1/test/chargerRectangle.php", id.ToString(),nomFigure);

            string json = httpRequest.LancerHTTPRequest();

            Rect RectTest = JsonConvert.DeserializeObject<Rect>(json);
            return RectTest;

        }
        public void save(Rect forme)
        {
            RequeteHTTP httpRequest = new RequeteHTTP("http://127.0.0.1/test/sauverRectangle.php", JsonConvert.SerializeObject(forme));
            string json = httpRequest.LancerHTTPRequest();

            Console.WriteLine(json);
            Console.ReadLine();
        }

        public bool isSameType(int id, string nomFigure)
        {
            RequeteHTTP httpRequest = new RequeteHTTP("http://127.0.0.1/test/type.php", id.ToString(), nomFigure);
            string type = httpRequest.LancerHTTPRequest();

            if (type == "rectangle") { return true; }
            else { return false; }
        }
    }
}
