<?php

namespace App\Models;

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

class TenantAdminPushSubscription extends Model
{
    /** @use HasFactory<\Database\Factories\TenantAdminPushSubscriptionFactory> */
    use HasFactory;

    protected $fillable = [
        'tenant_id',
        'user_id',
        'device_id',
        'endpoint',
        'endpoint_hash',
        'public_key',
        'auth_token',
        'content_encoding',
        'status',
        'expires_at',
        'last_seen_at',
        'last_notified_at',
        'last_failed_at',
        'failure_count',
        'language',
        'user_agent',
        'meta',
    ];

    protected $casts = [
        'expires_at' => 'datetime',
        'last_seen_at' => 'datetime',
        'last_notified_at' => 'datetime',
        'last_failed_at' => 'datetime',
        'meta' => 'array',
    ];

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

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