<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class FbDailySetting extends Model
{
    protected $fillable = [
        'date','password','amount_per_id','limit_per_user','is_active','upline_commissions'
    ];

    protected $casts = [
        'upline_commissions' => 'array',
        'is_active' => 'boolean',
    ];

    public static function effectiveForToday(): ?self
    {
        $today = now()->toDateString();

        $setting = static::query()
            ->where('date', $today)
            ->first();

        if ($setting) {
            return $setting;
        }

        return static::query()
            ->orderByDesc('date')
            ->first();
    }
}
