<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;
use Laravel\Sanctum\HasApiTokens;

class MemberUser extends Model
{
    use HasApiTokens, SoftDeletes;

    /**
     * 获取用户的默认地址
     */
    public function address()
    {
        return $this->hasOne(MemberAddress::class, 'user_id', 'id')->where('is_default', 1);
    }

    /**
     * 获取用户的所有地址
     */
    public function addresses(): HasMany
    {
        return $this->hasMany(MemberAddress::class, 'user_id', 'id');
    }

    /**
     * 获取用户的所有订单
     */
    public function orders(): HasMany
    {
        return $this->hasMany(Order::class, 'user_id', 'id');
    }
}
