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 DAOPolygone:IDAO<Polygone>
    {
        /*public Polygone charge(int id)
        {
            RequeteHTTP httpRequest = new RequeteHTTP("http://localhost/test/chargerPolygone.php", id.ToString());
            string json = httpRequest.LancerHTTPRequest();            

            Polygone polygoneTest = JsonConvert.DeserializeObject<Polygone>(json);
            return polygoneTest;            
        }*/

        public Polygone charge(int id, string nomfigure)
        {
            RequeteHTTP httpRequest = new RequeteHTTP("http://localhost/test/chargerPolygone.php", id.ToString(), nomfigure);
            string json = httpRequest.LancerHTTPRequest();

            Polygone polygoneTest = JsonConvert.DeserializeObject<Polygone>(json);
            return polygoneTest;
        }

        public void save(Polygone forme)
        {
            RequeteHTTP httpRequest = new RequeteHTTP("http://localhost/test/sauverPolygone.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://localhost/test/type.php", id.ToString(), nomFigure);
            string type = httpRequest.LancerHTTPRequest();

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