<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Sanctum\HasApiTokens;

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

    protected $fillable = [
        'name',
        'phone',
        'role',
        'fcm_token',
        'avatar_url',
    ];

    protected $hidden = [
        'fcm_token',
    ];

    // User ne konse circles banaye
    public function ownedCircles()
    {
        return $this->hasMany(Circle::class);
    }

    // User kin circles ka member hai
    public function circles()
    {
        return $this->belongsToMany(Circle::class, 'circle_members')
                    ->withPivot('role')
                    ->withTimestamps();
    }

    // User ki saari locations
    public function locations()
    {
        return $this->hasMany(Location::class);
    }

    // User ki latest location
    public function latestLocation()
    {
        return $this->hasOne(UserLatestLocation::class);
    }
}
