<?php

namespace App\Controllers\Seller\Warehouse;

use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;

use \App\Controllers\Container;

class ItemsDock extends Container
{
    public function get(Request $request, Response $response, $args)
    {
        $route = $request->getAttribute('route');
        $dock = $route->getArgument('dock');
        $item = $route->getArgument('item');

        $entityManager = $this->container->get('em');
        $stockRepository = $entityManager->getRepository('App\Models\Entity\StockDb');
        $stock = $stockRepository->findAll();

        foreach ($stock as $s) {
            if ($item == $s->getEan()) {
                $idStock = $s->getId();
            }
        }

        if (empty($idStock)) {
            throw new \Exception("Item nao cadastrado na base", 404);
        }

        switch ($dock) {
            case 'acreSergio':
                $idItem = $stockRepository->find($idStock);
                return $response->withJson($idItem, 200)->withHeader('Content-type', 'application/json');
                break;

            case 'Etq_Cmaleao':
                $idItem = $stockRepository->find($idStock);
                return $response->withJson($idItem, 200)->withHeader('Content-type', 'application/json');
                break;


            case 'outletCvto':
                $idItem = $stockRepository->find($idStock);
                return $response->withJson($idItem, 200)->withHeader('Content-type', 'application/json');
                break;

            case 'forMen':
                $idItem = $stockRepository->find($idStock);
                return $response->withJson($idItem, 200)->withHeader('Content-type', 'application/json');
                break;

            case 'maiusculo':
                $idItem = $stockRepository->find($idStock);
                return $response->withJson($idItem, 200)->withHeader('Content-type', 'application/json');
                break;

            case 'life':
                $idItem = $stockRepository->find($idStock);
                return $response->withJson($idItem, 200)->withHeader('Content-type', 'application/json');
                break;

            case 'vestylle':
                $idItem = $stockRepository->find($idStock);
                return $response->withJson($idItem, 200)->withHeader('Content-type', 'application/json');
                break;

            case 'haut':
                $idItem = $stockRepository->find($idStock);
                return $response->withJson($idItem, 200)->withHeader('Content-type', 'application/json');
                break;

            case 'dimazzo':
                $idItem = $stockRepository->find($idStock);
                return $response->withJson($idItem, 200)->withHeader('Content-type', 'application/json');
                break;

            case 'dimazzoArapongas':
                $idItem = $stockRepository->find($idStock);
                return $response->withJson($idItem, 200)->withHeader('Content-type', 'application/json');
                break;

            case 'bhPadilha':
                $idItem = $stockRepository->find($idStock);
                return $response->withJson($idItem, 200)->withHeader('Content-type', 'application/json');
                break;

            case 'origem':
                $idItem = $stockRepository->find($idStock);
                return $response->withJson($idItem, 200)->withHeader('Content-type', 'application/json');
                break;

            case 'emporio':
                $idItem = $stockRepository->find($idStock);
                return $response->withJson($idItem, 200)->withHeader('Content-type', 'application/json');
                break;

            case 'abusiva':
                $idItem = $stockRepository->find($idStock);
                return $response->withJson($idItem, 200)->withHeader('Content-type', 'application/json');
                break;

            case 'signoriOtto':
                $idItem = $stockRepository->find($idStock);
                return $response->withJson($idItem, 200)->withHeader('Content-type', 'application/json');
                break;

            case 'gianottoModas':
                $idItem = $stockRepository->find($idStock);
                return $response->withJson($idItem, 200)->withHeader('Content-type', 'application/json');
                break;

            default:
                throw new \Exception("Nao existe doca", 404);
                break;
        }
    }
}
