<?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
 * ============================================================
 */

namespace App\Models;

use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Prunable;

class MobileErrorLog extends Model
{
    use Prunable;

    public $timestamps = false;

    /**
     * Get the prunable model query.
     */
    public function prunable(): Builder
    {
        return self::query()->where('occurred_at', '<=', now()->subDays(90));
    }

    protected $fillable = [
        'user_id',
        'error_type',
        'message',
        'stack_trace',
        'platform',
        'app_version',
        'device_info',
        'occurred_at',
    ];

    protected $casts = [
        'device_info' => 'array',
        'occurred_at' => 'datetime',
    ];

    public function user()
    {
        return $this->belongsTo(User::class);
    }
}
