<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class MatchEvent extends Model
{
    use HasFactory;

    protected $fillable = [
        'match_id',
        'type',
        'side',
        'player',
        'assist',
        'player_in',
        'player_out',
        'description',
        'goal_kind',
        'minute',
        'second',
        'hidden',
        'team_name',
    ];

    protected $casts = [
        'minute' => 'integer',
        'second' => 'integer',
        'hidden' => 'boolean',
    ];

    public function match(): BelongsTo
    {
        return $this->belongsTo(FootballMatch::class, 'match_id');
    }

    public function toArray(): array
    {
        return [
            'id'          => $this->id,
            'type'        => $this->type,
            'side'        => $this->side,
            'player'      => $this->player,
            'assist'      => $this->assist,
            'playerIn'    => $this->player_in,
            'playerOut'   => $this->player_out,
            'description' => $this->description,
            'goalKind'    => $this->goal_kind,
            'minute'      => $this->minute,
            'second'      => $this->second,
            'hidden'      => $this->hidden,
            'team'        => $this->team_name,
            'at'          => $this->created_at?->timestamp * 1000,
        ];
    }
}
