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

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

            Segment segmentTest = JsonConvert.DeserializeObject<Segment>(json);
            return segmentTest;

        }

        public void save(Segment forme)
        {
            RequeteHTTP httpRequest = new RequeteHTTP("http://127.0.0.1/test/sauverSegment.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 == "segment") { return true; }
            else { return false; }
        }
    }
}
