<?php

namespace Kylin\Ecommerce\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\SoftDeletes;

/**
 * 收货地址模型
 *
 * 依据《个人信息保护法》第五十一条，
 * 收货人手机号需加密存储，展示时脱敏处理。
 */
class Address extends Model
{
    use SoftDeletes;

    protected $table = 'ecommerce_addresses';

    protected $fillable = [
        'user_id', 'receiver_name', 'receiver_phone',
        'province', 'city', 'district', 'detail',
        'postal_code', 'is_default', 'tag',
    ];

    protected $casts = [
        'is_default' => 'boolean',
    ];

    public function user(): BelongsTo
    {
        return $this->belongsTo(\App\Models\User::class);
    }
}