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

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

            string json = httpRequest.LancerHTTPRequest();
            //Console.WriteLine(json);

            //Triangle t1 = new Triangle("fraise", Color.Black, new PointForme(20, 50), new PointForme(30, 80), new PointForme(25, 135));
            //string output = JsonConvert.SerializeObject(t1);
            //Console.WriteLine(output);
            Triangle triangleTest = JsonConvert.DeserializeObject<Triangle>(json);
            return  triangleTest;                
            
        }*/

        public Triangle charge(int id, string nomFigure)
        {
            RequeteHTTP httpRequest = new RequeteHTTP("http://127.0.0.1/test/chargerTriangle.php", id.ToString(),nomFigure);

            string json = httpRequest.LancerHTTPRequest();
            Triangle triangleTest = JsonConvert.DeserializeObject<Triangle>(json);
            return triangleTest;
        }

        public void save(Triangle forme)
        {
            RequeteHTTP httpRequest = new RequeteHTTP("http://127.0.0.1/test/sauverTriangle.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 == "triangle") 
            {
                return true; 
            }
            else 
            {
                return false; 
            }
            //Console.WriteLine(json);
            //Console.ReadLine();
        }
    }
}
