<?php
declare(strict_types=1);
namespace Machweis\Backend;
use PDO;
final class IndustryProfileCatalog
{
/** @var array<string, string> */
public const PROFILES = [
'handwerk' => 'Handwerk',
'bau_montage' => 'Bau/Montage',
'containerdienst' => 'Containerdienst',
'entsorgung_recycling' => 'Entsorgung/Recycling',
'leckortung_rohrbruch' => 'Leckortung/Rohrbruch',
'facility_services' => 'Facility Services',
'sonstige_technische_dienste' => 'Sonstige technische Dienste',
];
/** @return list<string> */
public static function normalize(mixed $value): array
{
if (!is_array($value) || !array_is_list($value) || $value === []) {
throw new \InvalidArgumentException('At least one industry profile is required.');
}
$profiles = [];
foreach ($value as $profile) {
if (!is_string($profile) || !isset(self::PROFILES[$profile])) {
throw new \InvalidArgumentException('Unknown industry profile.');
}
if (!in_array($profile, $profiles, true)) $profiles[] = $profile;
}
return $profiles;
}
/** @param list<string> $profiles */
public static function assign(PDO $pdo, string $tenantId, array $profiles): void
{
$statement = $pdo->prepare('INSERT INTO tenant_industry_profiles (tenant_id, industry_code, created_at) VALUES (?, ?, UTC_TIMESTAMP())');
foreach ($profiles as $profile) $statement->execute([$tenantId, $profile]);
}
}
