<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class ReferralSetting extends Model
{
    protected $fillable = [
        'referrals_enabled',
        'invite_3_reward',
        'invite_10_reward',
        'mentor_20_students_reward',
        'bonus_text',
        'status',
    ];

    protected function casts(): array
    {
        return [
            'referrals_enabled' => 'boolean',
        ];
    }

    public static function current(): self
    {
        return self::query()->firstOrCreate([], [
            'referrals_enabled' => true,
            'invite_3_reward' => 'Reward placeholder for inviting 3 friends.',
            'invite_10_reward' => 'Reward placeholder for inviting 10 friends.',
            'mentor_20_students_reward' => 'Reward placeholder when a mentor brings 20 students.',
            'bonus_text' => 'Referral bonuses are placeholders until the admin connects a real reward policy.',
            'status' => 'active',
        ]);
    }

    public static function enabled(): bool
    {
        $settings = self::current();

        return $settings->referrals_enabled && $settings->status === 'active';
    }
}
