<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;

class Group extends Model
{
    public $timestamps = false;
    public $incrementing = false;
    protected $keyType = 'string';

    protected $fillable = [
        'id',
        'space_id',
        'name',
        'emoji',
        'type',
        'currency',
        'total_expenses',
        'created_at',
    ];

    protected $casts = [
        'total_expenses' => 'float',
        'created_at' => 'date',
    ];

    public function members(): BelongsToMany
    {
        return $this->belongsToMany(Person::class, 'group_members', 'group_id', 'person_id');
    }

    public function expenses(): HasMany
    {
        return $this->hasMany(Expense::class, 'group_id', 'id');
    }
}

