<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class TravelGroup extends Model
{
    protected $fillable = [
        'event_id',
        'name',
        'leader_user_id',
        'max_members',
        'preferences',
    ];

    protected $casts = [
        'preferences' => 'array',
    ];

    public function event()
    {
        return $this->belongsTo(Event::class);
    }

    public function leader()
    {
        return $this->belongsTo(User::class, 'leader_user_id');
    }

    public function members()
    {
        return $this->hasMany(TravelGroupMember::class, 'group_id');
    }

    public function acceptedMembers()
    {
        return $this->hasMany(TravelGroupMember::class, 'group_id')->where('status', 'accepted');
    }
}
