<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class SavingsTimeSetting extends Model
{
    use HasFactory;

    protected $fillable = [
        'name',
        'slug',
        'hours',
        'status',
    ];

    protected $casts = [
        'hours'  => 'integer',
        'status' => 'boolean',
    ];

    /**
     * Get all savings plans using this time setting.
     */
    public function savingsPlans()
    {
        return $this->hasMany(SavingsPlan::class, 'time_setting_id');
    }

    /**
     * Scope to only active time settings.
     */
    public function scopeActive($query)
    {
        return $query->where('status', true);
    }
}
