<?php

namespace Model;

use Entity\ImageEntity;
use Gateway\ImageGateway;
use Gateway\Gateway;

class ImageModel extends Model
{
    public function createImgModel(int $idImg, string $imgPath, bool $isImgProfile) : bool
    {
        return $this -> gateway -> createImgGateway($idImg, $imgPath, $isImgProfile);
    }

    public function getImgById(int $idImg) : ?ImageEntity
    {
        $res = $this -> gateway -> findImgById($idImg);

        if ($res)
        {
            return new ImageEntity(
                $res[0]['id_image'],
                $res[0]['img_path'],
                $res[0]['is_img_prfl']
            );
        }
        return null;
    }

    public function getAllImg() : array
    {
        $res = $this -> gateway -> findAllImg();

        $images = [];

        foreach ($res as $img)
        {
            $images[] = new ImageEntity(
                $img['id_image'],
                $img['img_path'],
                $img['is_img_prfl']
            );
        }
        return $images;
    }

    public function getAllImgProfile() : array
    {
        $res = $this -> gateway -> findAllImgProfile();

        $images = [];

        foreach ($res as $img)
        {
            $images[] = new ImageEntity(
                $img['id_image'],
                $img['img_path'],
                $img['is_img_prfl']
            );
        }
        return $images;
    }

    public function deleteImgModel(int $idImg) : bool
    {
        return $this -> gateway -> deleteImgGateway($idImg);
    }

    public function updateImgModel(int $idImg, string $imgPath) : bool
    {
        return $this -> gateway -> updateImgGateway($idImg, $imgPath);
    }
}