<?php
namespace Incoviba\Common\Controller;

use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Message\ResponseInterface as Response;
use \Model;
use Incoviba\Common\Define\Controller\Json;
use Incoviba\Venta;

class Ventas {
  use Json;

  public function __invoke(Request $request, Response $response): Response {
    $ventas = Model::factory(Venta::class)->find_array();
    $output = compact('ventas');
    return $this->withJson($response, $output);
  }
  public function show(Request $request, Response $response, $id_venta): Response {
    $venta = Model::factory(Venta::class)->find_one($id_venta);
    $output = ['venta' => $venta->as_array()];
    return $this->withJson($response, $output);
  }
  public function operador(Request $request, Response $response, $id_venta): Response {
    $venta = Model::factory(Venta::class)->find_one($id_venta);
    $output = [
      'venta' => $venta->as_array(),
      'operador' => $venta->operador() ? $venta->operador()->as_array() : null
    ];
    return $this->withJson($response, $output);
  }
}
