<?php

namespace App\Models;

use App\Models\Concerns\HasOwnerScope;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class Transaction extends Model
{
    use HasOwnerScope;

    protected $fillable = [
        'user_id',
        'external_id',
        'name',
        'category_id',
        'amount',
        'date',
        'type',
        'is_recurring',
        'recurring_frequency',
        'recurring_start_date',
        'notes',
    ];

    protected function casts(): array
    {
        return [
            'amount' => 'float',
            'date' => 'date',
            'is_recurring' => 'boolean',
            'recurring_start_date' => 'date',
        ];
    }

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