<?php

namespace Database;
use Model\Activity;

class ActivityMapper {
    public function activitySqlToEntity(array $data):array
    {
        $activityEntities = [];

        foreach ($data as $activityData) {
            $activity = new ActivityEntity();

            if (isset($activityData['idActivity'])) {
                $activity->setIdActivity($data['idActivity']);
            }

            if (isset($activityData['type'])) {
                $activity->setType($data['type']);
            }

            if (isset($activityData['date'])) {
                $activity->setDate($data['date']);
            }

            if (isset($activityData['heureDebut'])) {
                $activity->setHeureDebut($data['heureDebut']);
            }

            if (isset($activityData['heureFin'])) {
                $activity->setHeureFin($data['heureFin']);
            }

            if (isset($activityData['effortRessenti'])) {
                $activity->setEffortRessenti($data['effortRessenti']);
            }

            if (isset($activityData['variabilite'])) {
                $activity->setVariabilite($data['variabilite']);
            }

            if (isset($activityData['variance'])) {
                $activity->setVariance($data['variance']);
            }

            if (isset($activityData['ecartType'])) {
                $activity->setEcartType($data['ecartType']);
            }

            if (isset($activityData['moyenne'])) {
                $activity->setMoyenne($data['moyenne']);
            }

            if (isset($activityData['maximum'])) {
                $activity->setMaximum($data['maximum']);
            }

            if (isset($activityData['minimum'])) {
                $activity->setMinimum($data['minimum']);
            }

            if (isset($activityData['temperatureMoyenne'])) {
                $activity->setTemperatureMoyenne($data['temperatureMoyenne']);
            }

            $activityEntities[] = $activity;
        }

        return $activityEntities;
    }

    /**
     * @throws \Exception
     */
    public function ActivityEntityToModel(ActivityEntity $activiteEntity):Activity{

        $act = new Activity(
            $activiteEntity->getIdActivity(),
            $activiteEntity->getType(),
            $activiteEntity->getDate(),
            $activiteEntity->getHeureDebut(),
            $activiteEntity->getHeureFin(),
            $activiteEntity->getEffortRessenti(),
            $activiteEntity->getVariabilite(),
            $activiteEntity->getVariance(),
            $activiteEntity->getEcartType(),
            $activiteEntity->getMoyenne(),
            $activiteEntity->getMaximum(),
            $activiteEntity->getMinimum(),
            $activiteEntity->getTemperatureMoyenne()
        );

        return $act;
    }
    //public function ActivityToEntity(Activity model): ActivityEntity;

    public function activityToEntity(Activity $act):ActivityEntity{

        $act = new ActivityEntity();
        $act->setIdActivity($act->getIdActivity()());
        $act->setType($act->getType());
        $act->setDate($act->getDate());
        $act->setHeureDebut($act->getHeureDebut());
        $act->setHeureFin($act->getHeureFin());
        $act->setEffortRessenti($act->getEffortRessenti());
        $act->setVariabilite($act->getVariabilite());
        $act->setVariance($act->getVariance());
        $act->setEcartType($act->getEcartType());
        $act->setMoyenne($act->getMoyenne());
        $act->setMaximum($act->getMaximum());
        $act->setMinimum($act->getMinimum());
        $act->setTemperatureMoyenne($act->getTemperatureMoyenne());

        return $act;
    }
}

?>
