<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;

class User extends Authenticatable
{
    use HasFactory, Notifiable;

    protected $table = "users";
    public $timestamps = false; // shared schema: created_at only, set by DB default
    protected $fillable = ["email", "password_hash", "name", "phone", "is_admin"];
    protected $hidden = ["password_hash"];
    protected $casts = ["is_admin" => "boolean"];

    public function getAuthPassword(): string
    {
        return $this->password_hash;
    }

    public function tags(): HasMany
    {
        return $this->hasMany(Tag::class, "owner_id");
    }

    public function isAdmin(): bool
    {
        return (bool) $this->is_admin;
    }
}
