<?php

namespace App\Models;


use App\Notifications\ExpirySoonEmail;
use App\Notifications\ResetPasswordEmailTemplate;
use App\Notifications\UserNotify;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;

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

    /**
     * The attributes that are mass assignable.
     *
     * @var array<int, string>
     */
    protected $fillable = [
        'name',
        'email',
        'password',
    ];

    /**
     * The attributes that should be hidden for serialization.
     *
     * @var array<int, string>
     */
    protected $hidden = [
        'password',
        'remember_token',
    ];

    /**
     * Get the attributes that should be cast.
     *
     * @return array<string, string>
     */
    protected function casts(): array
    {
        return [
            'email_verified_at' => 'datetime',
            'password' => 'hashed',
        ];
    }

    public function sendPasswordResetNotification($token)
    {
        $this->notify(new ResetPasswordEmailTemplate($token));
    }

    public function userNotify($token)
    {
        $this->notify(new UserNotify($token));
    }

    public function expirySoon($token)
    {
        $this->notify(new ExpirySoonEmail($token));
    }

    public function orders()
    {
        return $this->hasMany(Order::class);
    }

    public function subscriber()
    {
        return $this->hasOne(Subscriber::class)->where('status', SUBSCRIBER_STATUS_ACTIVE);
    }

    public function package()
    {
        return $this->hasOne(Package::class)->where('status', PACKAGE_STATUS_ENABLE);
    }

    public function packages()
    {
        return $this->hasMany(Package::class);
    }

    public function replies()
    {
        return $this->hasMany(TicketReply::class);
    }

    public function tickets()
    {
        return $this->hasMany(SupportTicket::class);
    }

    public function appNotifications()
    {
        return $this->hasMany(AppNotification::class);
    }

    public function blogs()
    {
        return $this->hasMany(Blog::class);
    }
}
