<?php

namespace Dits\CaW\Configuration;

use Dits\CaW\DependencyInjection\Container;
use Dits\CaW\Rest\CompareClearRoute;
use Dits\CaW\Rest\CompareProductDeleteRoute;
use Dits\CaW\Rest\CompareProductPostRoute;
use Dits\CaW\Rest\CompareRoute;
use Dits\CaW\Rest\CompareTableRoute;
use Dits\CaW\Rest\RestApi;

class RestApiConfiguration implements ConfigurationInterface {

    public function modify( Container $container ) {
        $container['rest'] = $container->service( function ( Container $container ) {
            $routes = [];

            if ( $container['settings']->get( 'enable', 'compare' ) === 'on' ) {
                $routes = array_merge( $routes, [
                    new CompareRoute( $container['compare'] ),
                    new CompareClearRoute( $container['compare'] ),
                    new CompareTableRoute( $container['compare'] ),
                    new CompareProductPostRoute( $container['compare'] ),
                    new CompareProductDeleteRoute( $container['compare'] )
                ] );
            }

            return new RestApi( $container['plugin_dir'], $routes );
        } );
    }
}
