<?php

namespace app\admin\model;

use Throwable;
use think\model;
use think\Exception;
use think\model\relation\BelongsTo;

/**
 * UserScoreLog 模型
 * 1. 创建积分日志自动完成会员积分的添加
 * 2. 创建积分日志时，请开启事务
 */
class UserScoreLog extends model
{
    protected $autoWriteTimestamp = true;
    protected $updateTime         = false;

    const GAME_TYPE_LIST = [
        268 => 'plinko ball',
        269 => 'smash eggs',
        270 => 'spin wheel',
    ];

    public static function onBeforeDelete(): bool
    {
        return false;
    }

    public function user(): BelongsTo
    {
        return $this->belongsTo(User::class, 'user_id');
    }

    public function getGameTypeTextAttr($value, $data)
    {
        $gameType = $data['game_type'] ?? 0;
        return self::GAME_TYPE_LIST[$gameType] ?? 'Unknown Game';
    }

    protected $append = ['game_type_text'];

}