<?php

namespace api\classes;

use api\classes\API;
use api\classes\imageProcessor;

require_once 'API.php';

class API_usersavatar extends API
{

    public function createUserImage($imageRestrictions)
    {
        try {
            # Main image
            $imageProcessor = new imageProcessor('user_profile_picture');
            $imageProcessor->imageRestrictions = $imageRestrictions;
            $imageProcessor->validateAndProcess();
            $ImageData = $imageProcessor->returnBase64image();
        } catch (\RuntimeException $e) {
            $this->apiOutput(401, ['error' => 'Error: ' . $e->getMessage()]);
        }

        return $ImageData;
    }

    public function updateUserImage()
    {
        $query = "UPDATE system_users SET 
            user_profile_picture = ?,
            user_profile_picture_thumbnail = ?
        WHERE user_uuid = ?";

        $stmt = $this->prepareStatement($query);
        $stmt->bind_param("sss",
            $this->data['user_profile_picture'],
            $this->data['user_profile_picture_thumbnail'],
            $this->data['user_uuid']
        );
        $this->executeStatement($stmt);

    }

}