<?php

namespace App\Models\DTO\Toss;

use Illuminate\Contracts\Support\Responsable;
use Illuminate\Http\JsonResponse;

class FailData implements Responsable
{
    public string $resultType;
    public ?array $error;
    public ?array $success;

    public function __construct(string $errorCode, string $reason)
    {
        $this->resultType = 'FAIL';
        $this->error = [
            'errorCode' => $errorCode,
            'reason' => $reason
        ];
        $this->success = null;
    }

    public function __set($name, $value)
    {
        $this->{$name} = $value;
    }

    public function __get($name): mixed
    {
        return ($this->{$name} ?? null);
    }

    public function toResponse($request): JsonResponse
    {
        return response()->json($this);
    }
}
