<?php

namespace App\Models;

use App\Models\Enums\AccountStatusEnum;
use Illuminate\Auth\Notifications\VerifyEmail;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User;
use Illuminate\Notifications\Notifiable;
use Laravel\Sanctum\HasApiTokens;

/**
 * @property int $id
 * @property string $login
 * @property string $password
 * @property string $social_id
 * @property string $email
 * @property \Illuminate\Support\Carbon $create_time
 * @property AccountStatusEnum $status
 * @property string|null $securitycode
 * @property string $availDt
 * @property int $mileage
 * @property int $cash
 * @property string $gold_expire
 * @property string $silver_expire
 * @property string $safebox_expire
 * @property string $autoloot_expire
 * @property string $fish_mind_expire
 * @property string $marriage_fast_expire
 * @property string $money_drop_rate_expire
 * @property string|null $ip
 * @property string|null $last_play
 * @property-read \Illuminate\Notifications\DatabaseNotificationCollection<int, \Illuminate\Notifications\DatabaseNotification> $notifications
 * @property-read int|null $notifications_count
 * @property-read \Illuminate\Database\Eloquent\Collection<int, \Laravel\Sanctum\PersonalAccessToken> $tokens
 * @property-read int|null $tokens_count
 * @method static \Illuminate\Database\Eloquent\Builder<static>|Account newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder<static>|Account newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder<static>|Account query()
 * @method static \Illuminate\Database\Eloquent\Builder<static>|Account whereAutolootExpire($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|Account whereAvailDt($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|Account whereCash($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|Account whereCreateTime($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|Account whereEmail($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|Account whereFishMindExpire($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|Account whereGoldExpire($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|Account whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|Account whereIp($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|Account whereLastPlay($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|Account whereLogin($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|Account whereMarriageFastExpire($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|Account whereMileage($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|Account whereMoneyDropRateExpire($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|Account wherePassword($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|Account whereSafeboxExpire($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|Account whereSecuritycode($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|Account whereSilverExpire($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|Account whereSocialId($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|Account whereStatus($value)
 * @mixin \Eloquent
 */
class Account extends User implements MustVerifyEmail
{
    use HasApiTokens, HasFactory, Notifiable;

    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'account';

    /**
     * The name of the "created at" column.
     *
     * @var string|null
     */
    const CREATED_AT = 'create_time';

    /**
     * The name of the "updated at" column.
     *
     * @var string|null
     */
    const UPDATED_AT = null;

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

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

    /**
     * The attributes that should be cast.
     *
     * @var array<string, string>
     */
    protected $casts = [
        'email_verified_at' => 'datetime',
        'status' => AccountStatusEnum::class,
    ];

    /**
     * Determine if the user has verified their email address.
     */
    public function hasVerifiedEmail(): bool
    {
        return $this->status != AccountStatusEnum::NOT_AVAILABLE;
    }

    /**
     * Mark the given user's email as verified.
     */
    public function markEmailAsVerified(): bool
    {
        return $this->forceFill([
            'status' => AccountStatusEnum::OK,
        ])->save();
    }

    /**
     * Send the email verification notification.
     */
    public function sendEmailVerificationNotification(): void
    {
        $this->notify(new VerifyEmail);
    }

    /**
     * Get the email address that should be used for verification.
     */
    public function getEmailForVerification(): string
    {
        return $this->email;
    }
}
