<?php

namespace App\Models;

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

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

    protected $fillable = [
        'id',
        'space_id',
        'group_id',
        'shared_list_id',
        'description',
        'amount',
        'currency',
        'paid_by_person_id',
        'split_type',
        'split_among',
        'category',
        'emoji',
        'expense_date',
        'is_recurring',
    ];

    protected $casts = [
        'amount' => 'float',
        'split_among' => 'array',
        'expense_date' => 'date',
        'is_recurring' => 'bool',
    ];

    public function paidBy(): BelongsTo
    {
        return $this->belongsTo(Person::class, 'paid_by_person_id', 'id');
    }

    public function group(): BelongsTo
    {
        return $this->belongsTo(Group::class, 'group_id', 'id');
    }
}

