<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class PwaBonusLog extends Model
{
    const TABLE = 'agent.dbo.pwa_bonus_log';
    protected $table = self::TABLE;
    public $timestamps = false;

    protected $fillable = [
        'userID',
        'GameID',
        'Channel',
        'bonus_amount',
        'org_score',
        'now_score',
        'ip',
        'log_date',
        'created_at',
    ];

    public static function addLog(array $data)
    {
        $logData = [
            'userID' => $data['userID'] ?? null,
            'GameID' => $data['GameID'] ?? 0,
            'Channel' => $data['Channel'] ?? null,
            'bonus_amount' => $data['bonus_amount'] ?? 0,
            'org_score' => $data['org_score'] ?? 0,
            'now_score' => $data['now_score'] ?? 0,
            'ip' => $data['ip'] ?? null,
            'log_date' => $data['log_date'] ?? date('Y-m-d'),
            'created_at' => date('Y-m-d H:i:s'),
        ];

        return self::insert($logData);
    }
}
