<?php

namespace App\Models;

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

class RecurringExpense extends Model
{
    protected $fillable = [
        'business_id','branch_id','expense_category_id','financial_account_id','description','amount','supplier','start_date',
        'next_due_date','end_date','recurrence','interval_days','reminder_days_before','status','notes','created_by','updated_by',
    ];

    protected function casts(): array
    {
        return [
            'amount'=>'decimal:2','start_date'=>'date','next_due_date'=>'date','end_date'=>'date','interval_days'=>'integer',
            'reminder_days_before'=>'integer',
        ];
    }

    public function business(): BelongsTo { return $this->belongsTo(Business::class); }
    public function branch(): BelongsTo { return $this->belongsTo(Branch::class); }
    public function category(): BelongsTo { return $this->belongsTo(ExpenseCategory::class, 'expense_category_id'); }
    public function financialAccount(): BelongsTo { return $this->belongsTo(FinancialAccount::class); }
    public function creator(): BelongsTo { return $this->belongsTo(User::class, 'created_by'); }
    public function updater(): BelongsTo { return $this->belongsTo(User::class, 'updated_by'); }
    public function expenses(): HasMany { return $this->hasMany(Expense::class); }
    public function reminders(): HasMany { return $this->hasMany(ExpenseReminder::class); }
}