<?php

namespace App\Models;

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

class UserHub extends Model
{
    use HasFactory;

    protected $table = 'user_hubs';

    // ── Fillable ───────────────────────────────────────────────
    protected $fillable = [
        'user_id',
        'hub_id',
        'is_primary',
        'joined_at',
    ];

    // ── Casts ─────────────────────────────────────────────────
    protected $casts = [
        'is_primary' => 'boolean',
        'joined_at'  => 'datetime',
    ];

    // ── Relationships ─────────────────────────────────────────

    public function user(): BelongsTo
    {
        return $this->belongsTo(User::class);
    }

    public function hub(): BelongsTo
    {
        return $this->belongsTo(Hub::class);
    }
}
