using DTOs;
using Entities;
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ExtensionsClassLibrairie
{
    /// <summary>
    /// define some methods to manipulate entity, model and dto questions :
    /// convert model to DTO, model to Entity, ...
    /// and equality protocols
    /// </summary>
    public static class QuestionExtensionMethods
    {
        // conversion methods
        public static Question ToModel(this QuestionEntity q)
        {
            var tmp = new Question(q.Content, q.IdChapter, q.Id, q.IdAnswerGood);
            tmp.Difficulty = q.Difficulty;
            tmp.NbFalls = q.NbFalls;
            return tmp;
        }
        public static Question ToModel(this QuestionDto q)
        {
            var tmp = new Question(q.Content, q.IdChapter, q.Id, q.IdAnswerGood);
            tmp.Difficulty = q.Difficulty;
            tmp.NbFalls = q.NbFalls;
            return tmp;
        }
        public static QuestionDto ToDto(this Question q)
            => new QuestionDto { Id = q.Id, Content = q.Content, IdAnswerGood = q.IdAnswerGood,
                IdChapter = q.IdChapter, Difficulty = q.Difficulty, NbFalls = q.NbFalls };
        public static QuestionEntity ToEntity(this Question q)
            => new QuestionEntity { Id = q.Id, Content = q.Content, IdAnswerGood = q.IdAnswerGood,
                IdChapter = q.IdChapter, Difficulty = q.Difficulty, NbFalls = q.NbFalls };

        // reuse other methods
        public static QuestionDto ToDto(this QuestionEntity q)
            => q.ToModel().ToDto();
        public static QuestionEntity ToEntity(this QuestionDto q)
            => q.ToModel().ToEntity();
    }
}