<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Concerns\HasUuids;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Sanctum\HasApiTokens;

class User extends Authenticatable
{
    use HasApiTokens, HasFactory, HasUuids, Notifiable, SoftDeletes;

    protected $guarded = [];
    protected $hidden = ['password_hash', 'two_factor_secret'];
    protected $keyType = 'string';
    public $incrementing = false;

    public function getAuthPasswordName(): string
    {
        return 'password_hash';
    }

    protected function casts(): array
    {
        return [
            'phone_verified' => 'boolean', 'email_verified' => 'boolean',
            'two_factor_enabled' => 'boolean', 'last_login_at' => 'datetime',
            'locked_until' => 'datetime', 'deleted_at' => 'datetime',
        ];
    }

    public function partner(): HasOne { return $this->hasOne(Partner::class); }
    public function wallet(): HasOne { return $this->hasOne(Wallet::class); }
    public function bookings(): HasMany { return $this->hasMany(Booking::class); }
    public function reviews(): HasMany { return $this->hasMany(Review::class); }
    public function messages(): HasMany { return $this->hasMany(Message::class, 'sender_id'); }
    public function notifications(): HasMany { return $this->hasMany(Notification::class); }
    public function refreshTokens(): HasMany { return $this->hasMany(RefreshToken::class); }
    public function favorites(): HasMany { return $this->hasMany(Favorite::class); }
    public function passwordResets(): HasMany { return $this->hasMany(PasswordReset::class); }
}