src/Api/OpenAPI/Server/Controller/StudioController.php
<?php

/**
 * StudioController
 * PHP version 8.1.1.
 *
 * @category Class
 *
 * @author   OpenAPI Generator team
 *
 * @see     https://github.com/openapitools/openapi-generator
 */

/**
 * Catroweb API.
 *
 * API for the Catrobat Share Platform
 *
 * The version of the OpenAPI document: v1.6.0
 * Contact: webmaster@catrobat.org
 * Generated by: https://github.com/openapitools/openapi-generator.git
 */

/**
 * NOTE: This class is auto generated by the openapi generator program.
 * https://github.com/openapitools/openapi-generator
 * Do not edit the class manually.
 */

namespace OpenAPI\Server\Controller;

use JMS\Serializer\Exception\RuntimeException as SerializerRuntimeException;
use OpenAPI\Server\Api\StudioApiInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Symfony\Component\Validator\Constraints as Assert;

/**
 * StudioController Class Doc Comment.
 *
 * @category Class
 *
 * @author   OpenAPI Generator team
 *
 * @see     https://github.com/openapitools/openapi-generator
 */
class StudioController extends Controller
{
  /**
   * Operation studioIdDelete.
   *
   * Delete a studio (only available to studio admins)
   *
   * @param Request $request the Symfony request to handle
   *
   * @return Response the Symfony response
   */
  public function studioIdDeleteAction(Request $request, $id)
  {
    // Handle authentication
    // Authentication 'BearerAuth' required
    // HTTP bearer authentication required
    $securityBearerAuth = $request->headers->get('authorization');

    // Read out all input parameter values into variables
    $accept_language = $request->headers->get('Accept-Language', 'en');

    // Use the default value if no value was provided

    // Deserialize the input values that needs it
    try {
      $id = $this->deserialize($id, 'string', 'string');
      $accept_language = $this->deserialize($accept_language, 'string', 'string');
    } catch (SerializerRuntimeException $exception) {
      return $this->createBadRequestResponse($exception->getMessage());
    }

    // Validate the input values
    $asserts = [];
    $asserts[] = new Assert\NotNull();
    $asserts[] = new Assert\Type('string');
    $asserts[] = new Assert\Regex('/^[a-zA-Z0-9\-]+$/');
    $response = $this->validate($id, $asserts);
    if ($response instanceof Response) {
      return $response;
    }
    $asserts = [];
    $asserts[] = new Assert\Type('string');
    $response = $this->validate($accept_language, $asserts);
    if ($response instanceof Response) {
      return $response;
    }

    try {
      $handler = $this->getApiHandler();

      // Set authentication method 'BearerAuth'
      $handler->setBearerAuth($securityBearerAuth);

      // Make the call to the business logic
      $responseCode = 204;
      $responseHeaders = [];

      $handler->studioIdDelete($id, $accept_language, $responseCode, $responseHeaders);

      $message = match ($responseCode) {
        204 => 'OK',
        400 => 'Bad request (Invalid, or missing parameters)',
        401 => 'Invalid JWT token | JWT token not found | JWT token expired',
        403 => 'Insufficient privileges, action not allowed.',
        404 => 'Not found',
        406 => 'Not acceptable - client must accept application/json as content type',
        default => '',
      };

      return new Response(
        '',
        $responseCode,
        array_merge(
          $responseHeaders,
          [
            'X-OpenAPI-Message' => $message,
          ]
        )
      );
    } catch (\Throwable $fallthrough) {
      return $this->createErrorResponse(new HttpException(500, 'An unsuspected error occurred.', $fallthrough));
    }
  }

  /**
   * Operation studioIdGet.
   *
   * Get studio details (private studios are only available to members)
   *
   * @param Request $request the Symfony request to handle
   *
   * @return Response the Symfony response
   */
  public function studioIdGetAction(Request $request, $id)
  {
    // Figure out what data format to return to the client
    $produces = ['application/json'];
    // Figure out what the client accepts
    $clientAccepts = $request->headers->has('Accept') ? $request->headers->get('Accept') : '*/*';
    $responseFormat = $this->getOutputFormat($clientAccepts, $produces);
    if (null === $responseFormat) {
      return new Response('', 406);
    }

    // Handle authentication

    // Read out all input parameter values into variables
    $accept_language = $request->headers->get('Accept-Language', 'en');

    // Use the default value if no value was provided

    // Deserialize the input values that needs it
    try {
      $id = $this->deserialize($id, 'string', 'string');
      $accept_language = $this->deserialize($accept_language, 'string', 'string');
    } catch (SerializerRuntimeException $exception) {
      return $this->createBadRequestResponse($exception->getMessage());
    }

    // Validate the input values
    $asserts = [];
    $asserts[] = new Assert\NotNull();
    $asserts[] = new Assert\Type('string');
    $asserts[] = new Assert\Regex('/^[a-zA-Z0-9\-]+$/');
    $response = $this->validate($id, $asserts);
    if ($response instanceof Response) {
      return $response;
    }
    $asserts = [];
    $asserts[] = new Assert\Type('string');
    $response = $this->validate($accept_language, $asserts);
    if ($response instanceof Response) {
      return $response;
    }

    try {
      $handler = $this->getApiHandler();

      // Make the call to the business logic
      $responseCode = 200;
      $responseHeaders = [];

      $result = $handler->studioIdGet($id, $accept_language, $responseCode, $responseHeaders);

      $message = match ($responseCode) {
        200 => 'OK',
        400 => 'Bad request (Invalid, or missing parameters)',
        401 => 'Invalid JWT token | JWT token not found | JWT token expired',
        403 => 'Insufficient privileges, action not allowed.',
        404 => 'Not found',
        406 => 'Not acceptable - client must accept application/json as content type',
        default => '',
      };

      return new Response(
        null !== $result ? $this->serialize($result, $responseFormat) : '',
        $responseCode,
        array_merge(
          $responseHeaders,
          [
            'Content-Type' => $responseFormat,
            'X-OpenAPI-Message' => $message,
          ]
        )
      );
    } catch (\Throwable $fallthrough) {
      return $this->createErrorResponse(new HttpException(500, 'An unsuspected error occurred.', $fallthrough));
    }
  }

  /**
   * Operation studioIdPost.
   *
   * Update a Studio (only available to studio admins)
   *
   * @param Request $request the Symfony request to handle
   *
   * @return Response the Symfony response
   */
  public function studioIdPostAction(Request $request, $id)
  {
    // Figure out what data format to return to the client
    $produces = ['application/json'];
    // Figure out what the client accepts
    $clientAccepts = $request->headers->has('Accept') ? $request->headers->get('Accept') : '*/*';
    $responseFormat = $this->getOutputFormat($clientAccepts, $produces);
    if (null === $responseFormat) {
      return new Response('', 406);
    }

    // Handle authentication
    // Authentication 'BearerAuth' required
    // HTTP bearer authentication required
    $securityBearerAuth = $request->headers->get('authorization');

    // Read out all input parameter values into variables
    $accept_language = $request->headers->get('Accept-Language', 'en');
    $name = $request->request->get('name');
    $description = $request->request->get('description');
    $is_public = $request->request->get('is_public');
    $enable_comments = $request->request->get('enable_comments');
    $image_file = $request->files->get('image_file');

    // Use the default value if no value was provided

    // Deserialize the input values that needs it
    try {
      $id = $this->deserialize($id, 'string', 'string');
      $accept_language = $this->deserialize($accept_language, 'string', 'string');
      $name = $this->deserialize($name, 'string', 'string');
      $description = $this->deserialize($description, 'string', 'string');
      $is_public = $this->deserialize($is_public, 'bool', 'string');
      $enable_comments = $this->deserialize($enable_comments, 'bool', 'string');
    } catch (SerializerRuntimeException $exception) {
      return $this->createBadRequestResponse($exception->getMessage());
    }

    // Validate the input values
    $asserts = [];
    $asserts[] = new Assert\NotNull();
    $asserts[] = new Assert\Type('string');
    $asserts[] = new Assert\Regex('/^[a-zA-Z0-9\-]+$/');
    $response = $this->validate($id, $asserts);
    if ($response instanceof Response) {
      return $response;
    }
    $asserts = [];
    $asserts[] = new Assert\Type('string');
    $response = $this->validate($accept_language, $asserts);
    if ($response instanceof Response) {
      return $response;
    }
    $asserts = [];
    $asserts[] = new Assert\Type('string');
    $response = $this->validate($name, $asserts);
    if ($response instanceof Response) {
      return $response;
    }
    $asserts = [];
    $asserts[] = new Assert\Type('string');
    $response = $this->validate($description, $asserts);
    if ($response instanceof Response) {
      return $response;
    }
    $asserts = [];
    $asserts[] = new Assert\Type('bool');
    $response = $this->validate($is_public, $asserts);
    if ($response instanceof Response) {
      return $response;
    }
    $asserts = [];
    $asserts[] = new Assert\Type('bool');
    $response = $this->validate($enable_comments, $asserts);
    if ($response instanceof Response) {
      return $response;
    }
    $asserts = [];
    $asserts[] = new Assert\File();
    $response = $this->validate($image_file, $asserts);
    if ($response instanceof Response) {
      return $response;
    }

    try {
      $handler = $this->getApiHandler();

      // Set authentication method 'BearerAuth'
      $handler->setBearerAuth($securityBearerAuth);

      // Make the call to the business logic
      $responseCode = 200;
      $responseHeaders = [];

      $result = $handler->studioIdPost($id, $accept_language, $name, $description, $is_public, $enable_comments, $image_file, $responseCode, $responseHeaders);

      $message = match ($responseCode) {
        200 => 'Studio successfully updated.',
        400 => 'Bad request (Invalid, or missing parameters)',
        401 => 'Invalid JWT token | JWT token not found | JWT token expired',
        403 => 'Insufficient privileges, action not allowed.',
        404 => 'Not found',
        406 => 'Not acceptable - client must accept application/json as content type',
        422 => 'Unprocessable Entity (Specific error messages will be translated to the locale)',
        default => '',
      };

      return new Response(
        null !== $result ? $this->serialize($result, $responseFormat) : '',
        $responseCode,
        array_merge(
          $responseHeaders,
          [
            'Content-Type' => $responseFormat,
            'X-OpenAPI-Message' => $message,
          ]
        )
      );
    } catch (\Throwable $fallthrough) {
      return $this->createErrorResponse(new HttpException(500, 'An unsuspected error occurred.', $fallthrough));
    }
  }

  /**
   * Operation studioPost.
   *
   * Create a new Studio
   *
   * @param Request $request the Symfony request to handle
   *
   * @return Response the Symfony response
   */
  public function studioPostAction(Request $request)
  {
    // Figure out what data format to return to the client
    $produces = ['application/json'];
    // Figure out what the client accepts
    $clientAccepts = $request->headers->has('Accept') ? $request->headers->get('Accept') : '*/*';
    $responseFormat = $this->getOutputFormat($clientAccepts, $produces);
    if (null === $responseFormat) {
      return new Response('', 406);
    }

    // Handle authentication
    // Authentication 'BearerAuth' required
    // HTTP bearer authentication required
    $securityBearerAuth = $request->headers->get('authorization');

    // Read out all input parameter values into variables
    $accept_language = $request->headers->get('Accept-Language', 'en');
    $name = $request->request->get('name');
    $description = $request->request->get('description');
    $is_public = $request->request->get('is_public', true);
    $enable_comments = $request->request->get('enable_comments', true);
    $image_file = $request->files->get('image_file');

    // Use the default value if no value was provided

    // Deserialize the input values that needs it
    try {
      $accept_language = $this->deserialize($accept_language, 'string', 'string');
      $name = $this->deserialize($name, 'string', 'string');
      $description = $this->deserialize($description, 'string', 'string');
      $is_public = $this->deserialize($is_public, 'bool', 'string');
      $enable_comments = $this->deserialize($enable_comments, 'bool', 'string');
    } catch (SerializerRuntimeException $exception) {
      return $this->createBadRequestResponse($exception->getMessage());
    }

    // Validate the input values
    $asserts = [];
    $asserts[] = new Assert\Type('string');
    $response = $this->validate($accept_language, $asserts);
    if ($response instanceof Response) {
      return $response;
    }
    $asserts = [];
    $asserts[] = new Assert\Type('string');
    $response = $this->validate($name, $asserts);
    if ($response instanceof Response) {
      return $response;
    }
    $asserts = [];
    $asserts[] = new Assert\Type('string');
    $response = $this->validate($description, $asserts);
    if ($response instanceof Response) {
      return $response;
    }
    $asserts = [];
    $asserts[] = new Assert\Type('bool');
    $response = $this->validate($is_public, $asserts);
    if ($response instanceof Response) {
      return $response;
    }
    $asserts = [];
    $asserts[] = new Assert\Type('bool');
    $response = $this->validate($enable_comments, $asserts);
    if ($response instanceof Response) {
      return $response;
    }
    $asserts = [];
    $asserts[] = new Assert\File();
    $response = $this->validate($image_file, $asserts);
    if ($response instanceof Response) {
      return $response;
    }

    try {
      $handler = $this->getApiHandler();

      // Set authentication method 'BearerAuth'
      $handler->setBearerAuth($securityBearerAuth);

      // Make the call to the business logic
      $responseCode = 200;
      $responseHeaders = [];

      $result = $handler->studioPost($accept_language, $name, $description, $is_public, $enable_comments, $image_file, $responseCode, $responseHeaders);

      $message = match ($responseCode) {
        201 => 'Studio successfully created.',
        400 => 'Bad request (Invalid, or missing parameters)',
        401 => 'Invalid JWT token | JWT token not found | JWT token expired',
        406 => 'Not acceptable - client must accept application/json as content type',
        422 => 'Unprocessable Entity (Specific error messages will be translated to the locale)',
        default => '',
      };

      return new Response(
        null !== $result ? $this->serialize($result, $responseFormat) : '',
        $responseCode,
        array_merge(
          $responseHeaders,
          [
            'Content-Type' => $responseFormat,
            'X-OpenAPI-Message' => $message,
          ]
        )
      );
    } catch (\Throwable $fallthrough) {
      return $this->createErrorResponse(new HttpException(500, 'An unsuspected error occurred.', $fallthrough));
    }
  }

  /**
   * Returns the handler for this API controller.
   *
   * @return StudioApiInterface
   */
  public function getApiHandler()
  {
    return $this->apiServer->getApiHandler('studio');
  }
}
