<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class PushDeviceToken extends Model
{
    use HasFactory;

    protected $fillable = [
        'user_id',
        'provider',
        'platform',
        'token',
        'device_name',
        'last_seen_at',
        'disabled_at',
    ];

    protected function casts(): array
    {
        return [
            'last_seen_at' => 'datetime',
            'disabled_at' => 'datetime',
        ];
    }

    public function scopeActive(Builder $query): Builder
    {
        return $query->whereNull('disabled_at');
    }

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