<?php

namespace App\Models;

use App;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Sanctum\HasApiTokens;
use App\Models\Promocode;

class Member extends Authenticatable
{
    use HasApiTokens;
    use Notifiable;

    protected $table = 'members';
    /**
     * 可填充的屬性。
     *
     * @var array<int, string>
     */
    protected $fillable = [
        'name',
        'email',
        'avatar',
        'phone',
        'source',
        'password',
        'line_id',
    ];

    // 定義 Level 描述對應
    public static $levelName = [
        0 => '一般會員',
        1 => '白銀會員',
        2 => '白金會員',
        9 => '管理員',
    ];

    // 訪問器：自動轉換 Level
    public function getLevelNameAttribute()
    {
        return self::$levelName[$this->level] ?? '未知會員';
    }

    /**
     * 隱藏的屬性。
     *
     * @var array<int, string>
     */
    protected $hidden = [
        'password',
        'remember_token',
    ];

    /**
     * 屬性轉型。
     *
     * @var array<string, string>
     */
    protected $casts = [
        'email_verified_at' => 'datetime',
    ];


    public function getPromoCode()
    {
        return $this->hasMany(Promocode::class, 'giveto_mem_id', 'id');
    }
    protected function casts(): array
    {
        return [
            'email_verified_at' => 'datetime',
            'password' => 'hashed',
        ];
    }
}
