Agrego archivos iniciales
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\AI\Tools;
|
||||
|
||||
use App\Models\Evento;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class CrearPartidoTool
|
||||
{
|
||||
public function __invoke(
|
||||
int $id_equipo_local,
|
||||
int $id_equipo_visitante,
|
||||
string $fecha_evento,
|
||||
string $hora_inicio,
|
||||
string $hora_fin,
|
||||
string $sede,
|
||||
int $id_torneo,
|
||||
?float $precio = null
|
||||
): string {
|
||||
try {
|
||||
$evento = Evento::create([
|
||||
'id_evento' => (string) Str::uuid(),
|
||||
'id_equipo_local' => $id_equipo_local,
|
||||
'id_equipo_visitante' => $id_equipo_visitante,
|
||||
'fecha_evento' => $fecha_evento,
|
||||
'hora_inicio' => str_contains($hora_inicio, ':') ? $hora_inicio . (strlen($hora_inicio) === 5 ? ':00' : '') : $hora_inicio,
|
||||
'hora_fin' => str_contains($hora_fin, ':') ? $hora_fin . (strlen($hora_fin) === 5 ? ':00' : '') : $hora_fin,
|
||||
'sede' => $sede,
|
||||
'id_torneo' => $id_torneo,
|
||||
'precio' => $precio ?? 0,
|
||||
'fase' => Evento::FASE_REGULAR,
|
||||
]);
|
||||
|
||||
return json_encode([
|
||||
'success' => true,
|
||||
'id_evento' => $evento->id_evento,
|
||||
'mensaje' => "Partido creado correctamente. ID: {$evento->id_evento}",
|
||||
]);
|
||||
} catch (\Throwable $e) {
|
||||
return json_encode(['error' => 'No se pudo crear el partido: ' . $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user