<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Relations\BelongsTo;

/**
 * 后台用户扩展数据
 *
 * 存储后台用户(admin_users)的扩展字段实际值，
 * 每个用户+字段一条记录。
 */
class AdminUserExtData extends BaseModel
{
    protected $table = 'admin_user_ext_data';

    public const CREATED_AT = 'create_time';
    public const UPDATED_AT = 'update_time';

    protected $fillable = [
        'admin_user_id',
        'field_id',
        'field_value',
    ];

    protected $casts = [
        'admin_user_id' => 'integer',
        'field_id' => 'integer',
    ];

    /**
     * 关联后台用户
     */
    public function adminUser(): BelongsTo
    {
        return $this->belongsTo(AdminUser::class, 'admin_user_id');
    }

    /**
     * 关联字段定义
     */
    public function field(): BelongsTo
    {
        return $this->belongsTo(AdminUserExtField::class, 'field_id');
    }
}
