<?php

/**
 * ============================================================
 *
 * @project   biiproject
 *
 * @author    Andika Debi Putra
 *
 * @email     andikadebiputra@gmail.com
 *
 * @website   https://biiproject.com
 *
 * @copyright Copyright (c) 2026 Andika Debi Putra
 * @license   Proprietary - All Rights Reserved
 *
 * @version   1.0.0
 *
 * @created   2026-05-01
 * ============================================================
 *
 * Unauthorized copying, modification, distribution, or use
 * of this file is strictly prohibited without prior written
 * permission from the author.
 * ============================================================
 */

namespace App\Models;

use App\Services\MobileConfig\MobileConfigService;
use Illuminate\Database\Eloquent\Model;
use Spatie\Activitylog\LogOptions;
use Spatie\Activitylog\Traits\LogsActivity;

class MobileSetting extends Model
{
    use LogsActivity;

    protected $fillable = [
        'key',
        'value',
        'group',
        'type',
    ];

    /**
     * Spatie Activitylog configuration
     */
    public function getActivitylogOptions(): LogOptions
    {
        return LogOptions::defaults()
            ->useLogName('mobile-config')
            ->logOnly(['key', 'value', 'group', 'type'])
            ->logOnlyDirty()
            ->dontSubmitEmptyLogs();
    }

    protected static function booted()
    {
        static::saved(fn () => MobileConfigService::clearCacheStatic());
        static::deleted(fn () => MobileConfigService::clearCacheStatic());
    }
}
