<?php

namespace Controllers;

use Libs\ResponseLib;
use Psr\Http\Message\ServerRequestInterface;
use Respect\Validation\Exceptions\ValidationException;
use Respect\Validation\Validator as val;
use React\Http\Message\Response;

class CompanyCheckStatus
{
    public function __invoke(ServerRequestInterface $request)
    {
        $body = json_decode((string)$request->getBody(), true) ?? [];

        try {
            val::key('numberToken', val::stringType()->notEmpty()->length(1, 255))
                ->assert($body);
        } catch (ValidationException $e) {
            return ResponseLib::sendFail("Validation failed: " . $e->getFullMessage(), [], "E_VALIDATE")->withStatus(400);
        }

        $numberToken = trim($body['numberToken']);
        $mockStatuses = [
            'abcd-efgh-1234' => 1,
            'ijkl-mnop-5678' => 2,
        ];

        $status = $mockStatuses[$numberToken] ?? 0;

        return Response::json(['status' => $status])->withStatus(200);
    }
}
