<?php
/**
 * @param string $gameFileName
 * @param string $gameFileTmp
 * @return string
 */

function ZipFileHandler(string $gameFileName, string $gameFileTmp): string
{
    $fileExtGame = explode('.', $gameFileName);
    $fileActualExtGame = strtolower(end($fileExtGame));

    $headerType = mime_content_type($gameFileTmp);
    $headerTypeMatch = array('application/zip');

    if(in_array($headerType,$headerTypeMatch)){
        $gameFileNewName = uniqid("", true). "." .  $fileActualExtGame;
        if(empty($gameFileName)){
            http_response_code(400);
            exit();
        }
        rename($gameFileTmp,"../../Games/".$gameFileNewName);
        return $gameFileNewName;
    }else{
        http_response_code(400);
        echo json_encode(["message" => "Wrong file type gameFile"]);
        exit();
    }
}

/**
 * @param string $thumbnailFileName
 * @param string $thumbnailFileTmp
 * @return string
 */
function imagesFileHandler(string $thumbnailFileName, string $thumbnailFileTmp): string
{
    $fileExtThumb = explode('.', $thumbnailFileName);
    $fileActualExtThumb = strtolower(end($fileExtThumb));

    $headerType = mime_content_type($thumbnailFileTmp);
    $headerTypeMatch = array('image/png', 'image/jpeg','image/gif', 'image/svg+xml',);

    if(in_array($headerType,$headerTypeMatch)){
        $thumbnailFileNewName = uniqid("", true). "." .  $fileActualExtThumb;
        if(empty($thumbnailFileName)){
            http_response_code(400);
            exit();
        }
        rename($thumbnailFileTmp,"../../../Frontend/images/".$thumbnailFileNewName);
        return $thumbnailFileNewName;
    }else{
        http_response_code(400);
        echo json_encode(["message" => "Wrong file type thumbnailFile"]);
        exit();
    }
}