<?php


use api\classes\API_usersavatar;

session_start();
require_once "{$_SERVER['DOCUMENT_ROOT']}/api/classes/API_usersavatar.php";
require_once "{$_SERVER['DOCUMENT_ROOT']}/api/classes/imageProcessor.php";

$API_usersavatar = new API_usersavatar();

if ($API_usersavatar->request_method === 'POST') {
    # Reset a users password and send an email the user to set a new password

    $API_usersavatar->postedData['user_profile_picture'] = $API_usersavatar->createUserImage(['min_width' => 500, 'max_width' => 1000, 'min_height' => 500, 'max_height' => 1000, 'square' => true, 'allowed_types' => ['image/png'], 'max_size_kb' => 1024, 'transparent' => true]);
    $API_usersavatar->postedData['user_profile_picture_thumbnail'] = $API_usersavatar->createUserImage(['min_width' => 64, 'max_width' => 64, 'min_height' => 64, 'max_height' => 64, 'square' => true, 'allowed_types' => ['image/png'], 'max_size_kb' => 1024, 'transparent' => true]);

    $requiredFields = [
        'user_uuid' => ['type' => 'uuid'],
        'user_profile_picture' => ['type' => 'base64'],
        'user_profile_picture_thumbnail' => ['type' => 'base64'],
    ];

    $API_usersavatar->validateData($requiredFields);

    # if the user is different from the user logged in, check the required permissions
    if ($API_usersavatar->data['user_uuid'] != $API_usersavatar->getUserUuid()) {
        $API_usersavatar->checkPermissions('admin-access-admins', 'RW');
    }

    $API_usersavatar->updateUserImage();

    $API_usersavatar->apiOutput(200, ['success' => 'Avatar was successfully changed.']);

}