<?php

namespace App\Models;

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



class UserDevice extends Model
{
    protected $hidden = ['api_token'];
    protected $fillable = [
        'user_id',
        'device_id',
        'name',
        'model',
        'platform',
        'operating_system',
        'os_version',
        'manufacturer',
        'is_virtual',
        'web_view_version',
        'app_version',
        'app_build',
        'locale',
        'ip_address',
        'user_agent',
        'api_token',
        'status',
        'fcm_token',
        'last_login_at',
        'last_seen_at',
        'last_logout_at',
    ];

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

    public function smsMessages(): \Illuminate\Database\Eloquent\Relations\HasMany
    {
        return $this->hasMany(SmsMessage::class, 'device_id');
    }

    public function validate(array $input)
    {
        return \Illuminate\Support\Facades\Validator::make($input, [
            'name' => 'nullable|string|max:255',
            'status' => 'nullable|in:0,1',
        ]);
    }

    /**
     * @return array<string, string>
     */
    protected function casts(): array
    {
        return [
            'status' => 'integer',
            'is_virtual' => 'boolean',
            'last_login_at' => 'datetime',
            'last_seen_at' => 'datetime',
            'last_logout_at' => 'datetime',
        ];
    }
}
