<?php

namespace Modules\VetClinic\Entities;

use Illuminate\Database\Eloquent\Model;

class VcReminderSetting extends Model
{
    protected $table = 'vc_reminder_settings';

    protected $fillable = [
        'business_id',
        'is_enabled',
        'days_before_due',
        'send_overdue',
        'overdue_reminder_interval',
        'max_reminders_per_vaccine',
        'email_enabled',
        'wa_enabled',
        'schedule_time',
    ];

    protected $casts = [
        'is_enabled'    => 'boolean',
        'send_overdue'  => 'boolean',
        'email_enabled' => 'boolean',
        'wa_enabled'    => 'boolean',
    ];

    /**
     * Get or create settings for a business with sensible defaults.
     */
    public static function forBusiness(int $businessId): self
    {
        return static::firstOrCreate(
            ['business_id' => $businessId],
            [
                'is_enabled'                => true,
                'days_before_due'           => 7,
                'send_overdue'              => true,
                'overdue_reminder_interval' => 7,
                'max_reminders_per_vaccine' => 3,
                'email_enabled'             => true,
                'wa_enabled'                => false,
                'schedule_time'             => '08:00',
            ]
        );
    }
}
