55 lines
2.1 KiB
PHP
55 lines
2.1 KiB
PHP
<?php
|
|
namespace App\Services;
|
|
|
|
use App\Models\Opportunity;
|
|
use App\Models\Sector;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
|
|
/** Tempo, 18/10/2026: existing masters, one specialization, historical combined bridge. */
|
|
final class SectorOrganization
|
|
{
|
|
public const LEGACY_COMBINED = 'energia';
|
|
public const FINTECH = 'fintech';
|
|
public const LEGACY_ACTIVITY_ID = 'a2000000-0000-4000-8000-000000000002';
|
|
|
|
public static function href(string $slug): string
|
|
{
|
|
return match ($slug) {
|
|
'energia' => '/energia-mineracao',
|
|
'fintech' => '/sectores/mercado-financeiro/fintech',
|
|
default => '/sectores/'.$slug,
|
|
};
|
|
}
|
|
|
|
/** A historical combined filter remains a union, never an arbitrary reassignment. */
|
|
public static function slugs(string $slug): array
|
|
{
|
|
return match ($slug) {
|
|
'energia', 'energia-mineracao' => ['energia', 'energia-especifica', 'mineracao'],
|
|
'mercado-financeiro' => ['mercado-financeiro', 'fintech'],
|
|
'mercado-financeiro/fintech' => ['fintech'],
|
|
default => [$slug],
|
|
};
|
|
}
|
|
|
|
public static function constrain(Builder $query, string $slug): Builder
|
|
{
|
|
return $query->whereHas('sector', fn ($s) => $s->whereIn('slug', self::slugs($slug)));
|
|
}
|
|
|
|
public static function opportunities(Sector $sector): Builder
|
|
{
|
|
return self::constrain(Opportunity::published(), $sector->slug);
|
|
}
|
|
|
|
public static function catalog()
|
|
{
|
|
return Sector::catalog()->orderBy('sort_order')->get()->each(function ($sector) {
|
|
$sector->setAttribute('opportunities_count', self::opportunities($sector)->count());
|
|
$sector->setAttribute('url', self::href($sector->slug));
|
|
$sector->setAttribute('specializations', $sector->slug === 'mercado-financeiro'
|
|
? Sector::where('slug', 'fintech')->where('is_active', true)->whereNotNull('published_at')->get(['id', 'name', 'slug'])->map(fn ($s) => [...$s->only(['id', 'name', 'slug']), 'url' => self::href($s->slug)])->all() : []);
|
|
});
|
|
}
|
|
}
|