<?php

namespace App\Http\Controllers\ParentPortal\Concerns;

use App\Models\Family;

trait ResolvesFamily
{
    protected function family(): Family
    {
        $family = auth()->user()->family;

        abort_if(! $family, 403, 'No family is linked to this account.');

        return $family;
    }

    /** Ensure a student belongs to the logged-in parent's family. */
    protected function authorizeChild(\App\Models\Student $student): void
    {
        abort_unless($student->family_id === $this->family()->id, 403);
    }
}
