<?php
use ProVM\Money\Common\Controller\Currencies;

$app->group('/currencies', function($app) {
  $app->post('/add[/]', [Currencies::class, 'add']);
  $app->get('[/]', Currencies::class);

  $app->options('[/]', function (Request $request, Response $response): Response {
    return $response;
  });
});

$app->group('/currency/{currency_id:[0-9]+}', function($app) {
  $app->put('/edit[/]', [Currencies::class, 'edit']);
  $app->delete('/delete[/]', [Currencies::class, 'delete']);
  $app->group('/aliases', function($app) {
    $app->post('/add[/]', [Currencies::class, 'addAliases']);
    $app->get('[/]', [Currencies::class, 'getAliases']);
    $app->options('[/]', function (Request $request, Response $response): Response {
      return $response;
    });
  });
  $app->group('/values', function($app) {
    $app->get('/latest[/]', [Currencies::class, 'latestValue']);
    $app->post('/add[/]', [Currencies::class, 'addValues']);
    $app->get('[/]', [Currencies::class, 'getValues']);
    $app->options('[/]', function (Request $request, Response $response): Response {
      return $response;
    });
  });
  $app->group('/sources', function($app) {
    $app->post('/add[/]', [Currencies::class, 'addSources']);
    $app->get('[/]', [Currencies::class, 'getSources']);
    $app->options('[/]', function (Request $request, Response $response): Response {
      return $response;
    });
  });
  $app->get('[/]', [Currencies::class, 'get']);
  $app->options('[/]', function (Request $request, Response $response): Response {
    return $response;
  });
});

$app->group('/currency/{query:[a-z]+}', function($app) {
  $app->group('/values', function($app) {
    $app->get('/latest[/]', [Currencies::class, 'findLatest']);
    $app->get('[/]', [Currencies::class, 'findValues']);
    $app->options('[/]', function (Request $request, Response $response): Response {
      return $response;
    });
  });
  $app->get('/sources', [Currencies::class, 'findSources']);
  $app->get('[/]', [Currencies::class, 'find']);
  $app->options('[/]', function (Request $request, Response $response): Response {
    return $response;
  });
});
