<?php

namespace App\Models;

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

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

    /**
     * The attributes that are mass assignable.
     *
     * @var array<int, string>
     */
    protected $table = "telemed_pros";
    protected $fillable = [
        'name',
        'first_name',
        'last_name',
        'email',
        'password',
        'is_busy',
        'recording_switch',
        "ai_switch",
        "status",
        "practice_state",
        "phone_number",
        "gender",
        "specialty",
        "home_address",
        "medical_license_number",
        "years_of_experience",
        "email_verification",
        "city",
        "state",
        "zip_code",
        "availability_to",
        "availability_from"
    ];
    protected $hidden = [
        'password',
        'remember_token',
    ];
    protected $casts = [
        'email_verified_at' => 'datetime',
        'password' => 'hashed',
        /* 'state' => 'array', */
    ];

    public function appointments()
    {
        return $this->hasMany(Appointment::class, 'telemed_pros_id');
    }

    public function getMeetingCountAttribute()
    {
        return $this->appointments()
            ->whereHas('cart', function ($query) {
                $query->whereNotNull('appointment_id');
            })
            ->count();
    }
}
