namespace App\Models;
+use App\Events\ProtocolAdded;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
{
use HasFactory;
+ public static function resultReported(Tournament $tournament, Result $result, User $user) {
+ $protocol = static::create([
+ 'tournament_id' => $tournament->id,
+ 'user_id' => $user->id,
+ 'type' => 'result.report',
+ 'details' => [
+ 'tournament' => static::tournamentMemo($tournament),
+ 'result' => static::resultMemo($result),
+ ],
+ ]);
+ ProtocolAdded::dispatch($protocol);
+ }
+
+ public static function roundAdded(Tournament $tournament, Round $round, User $user) {
+ $protocol = static::create([
+ 'tournament_id' => $tournament->id,
+ 'user_id' => $user->id,
+ 'type' => 'round.create',
+ 'details' => [
+ 'tournament' => static::tournamentMemo($tournament),
+ 'round' => static::roundMemo($round),
+ ],
+ ]);
+ ProtocolAdded::dispatch($protocol);
+ }
+
+ public static function roundSeedSet(Tournament $tournament, Round $round, User $user) {
+ $protocol = static::create([
+ 'tournament_id' => $tournament->id,
+ 'user_id' => $user->id,
+ 'type' => 'round.create',
+ 'details' => [
+ 'tournament' => static::tournamentMemo($tournament),
+ 'round' => static::roundMemo($round),
+ ],
+ ]);
+ ProtocolAdded::dispatch($protocol);
+ }
+
+ public static function tournamentCreated(Tournament $tournament, User $user) {
+ $protocol = static::create([
+ 'tournament_id' => $tournament->id,
+ 'user_id' => $user->id,
+ 'type' => 'tournament.create',
+ 'details' => [
+ 'tournament' => static::tournamentMemo($tournament),
+ ],
+ ]);
+ ProtocolAdded::dispatch($protocol);
+ }
+
+
+ protected static function resultMemo(Result $result) {
+ return [
+ 'id' => $result->id,
+ 'time' => $result->time,
+ ];
+ }
+
+ protected static function roundMemo(Round $round) {
+ return [
+ 'id' => $round->id,
+ 'seed' => $round->seed,
+ ];
+ }
+
+ protected static function tournamentMemo(Tournament $tournament) {
+ return [
+ 'id' => $tournament->id,
+ 'title' => $tournament->title,
+ ];
+ }
+
+ protected static function userMemo(User $user) {
+ return [
+ 'id' => $user->id,
+ 'username' => $user->username,
+ 'discriminator' => $user->discriminator,
+ 'avatar' => $user->avatar,
+ ];
+ }
+
+
public function tournament() {
return $this->belongsTo(Tournament::class);
}
return $this->belongsTo(User::class);
}
+
+ protected $casts = [
+ 'details' => 'array',
+ ];
+
+ protected $fillable = [
+ 'details',
+ 'tournament_id',
+ 'type',
+ 'user_id',
+ ];
+
}