<?php

use api\classes\API_companies;

session_start();

require_once "{$_SERVER['DOCUMENT_ROOT']}/api/classes/API_companies.php";

# Check permissions
$API_companies = new API_companies();

if (!$GLOBALS['modules_enabled']['customers']) {
    echo '405 Not Allowed';
    exit;
}

if ($API_companies->request_method === 'PUT') {
    $API_companies->checkPermissions('customer-companies', 'RW');

    # when called from the frontend will not be forwarding to a url since when it's called from the frontend it doesn't need a redirection
    $API_companies->return_url = false;

    $requiredFields = [
        'company_uuid' => ['type' => 'uuid'],
        'company_state' => ['type' => 'enum', 'values' => ['active', 'imported', 'orphaned']]
    ];

    $API_companies->validateData($requiredFields);

    $API_companies->updateCompanyState();

}