<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class TossCertLog extends Model
{
    protected $table = 'tb_toss_cert_log';
    protected $primaryKey = 'id';

    public $keyType = 'int';
    public $incrementing = false;
    public $timestamps = false;

    const CREATED_AT = 'created_at';
    const UPDATED_AT = null;
    const DELETED_AT = null;

    protected $guarded = [];

    /**
     * 토스 인증 기록 등록
     */
    public function register(object $result): bool
    {
        return $this->insert([
            'resultType' => $result->resultType,
            'txId' => $result->success->txId,
            'status' => $result->success->status,
            'userIdentifier' => $result->success->userIdentifier,
            'userCiToken' => $result->success->userCiToken,
            'randomValue' => $result->success->randomValue,
            'completedDt' => now()->setDateTimeFrom($result->success->completedDt),
            'requestedDt' => now()->setDateTimeFrom($result->success->requestedDt),
            'personalData' => json_encode(get_object_vars($result->success->personalData))
        ]);
    }
}
