<?php

namespace App\Repositories;

use App\Contracts\Repositories\TeamRepositoryInterface;
use App\Models\Team;
use Illuminate\Database\Eloquent\Collection;

class TeamRepository implements TeamRepositoryInterface
{
    public function findOrFail(int $id): Team
    {
        return Team::with('players')->findOrFail($id);
    }

    public function all(): Collection
    {
        return Team::with('players')->orderBy('name')->get();
    }

    public function create(array $data): Team
    {
        return Team::create($data);
    }

    public function update(Team $team, array $data): Team
    {
        $team->update($data);

        return $team->fresh('players');
    }

    public function delete(Team $team): void
    {
        $team->delete();
    }
}
