29 lines
1.2 KiB
PHP
29 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Services;
|
|
|
|
use App\Models\Tenant;
|
|
use Illuminate\Support\Facades\Validator;
|
|
|
|
class IntelligencePolicy
|
|
{
|
|
/** @return array{revision:int,configured:bool,procurement_brief:bool,people_brief:bool,ai_plan?:array<string,mixed>} */
|
|
public function company(Tenant $company): array
|
|
{
|
|
$stored = array_key_exists('intelligence_policy', $company->getAttributes()) ? $company->intelligence_policy : null;
|
|
|
|
return $stored ?? ['revision' => 0, 'configured' => false, 'procurement_brief' => true, 'people_brief' => true];
|
|
}
|
|
|
|
/** @param array<string,mixed> $input
|
|
* @return array{revision:int,configured:bool,procurement_brief:bool,people_brief:bool,ai_plan?:array<string,mixed>}
|
|
*/
|
|
public function next(Tenant $company, array $input): array
|
|
{
|
|
$values = Validator::make($input, ['procurement_brief' => 'required|boolean', 'people_brief' => 'required|boolean'])->validate();
|
|
|
|
return [...$this->company($company), 'revision' => $this->company($company)['revision'] + 1, 'configured' => true,
|
|
'procurement_brief' => (bool) $values['procurement_brief'], 'people_brief' => (bool) $values['people_brief']];
|
|
}
|
|
}
|