<?php

namespace App\Models\DTO\Toss;

use Illuminate\Contracts\Support\Arrayable;

class AuthData implements Arrayable
{
    public string $requestType;
    public ?string $triggerType;
    public ?string $userName;
    public ?string $userPhone;
    public ?string $userBirthday;
    public ?string $sessionKey;
    public ?string $successCallbackUrl;
    public ?string $failCallbackUrl;
    public ?string $nonce;
    public ?int $expireSeconds;

    public function __construct(
        string $requestType, ?string $triggerType = null,
        ?string $userName = null, ?string $userPhone = null, ?string $userBirthday = null,
        ?string $sessionKey = null, ?string $successCallbackUrl = null, ?string $failCallbackUrl = null,
        ?string $nonce = null, ?int $expireSeconds = null,
    ) {
        $this->requestType = $requestType;
        $this->triggerType = $triggerType;
        $this->userName = $userName;
        $this->userPhone = $userPhone;
        $this->userBirthday = $userBirthday;
        $this->sessionKey = $sessionKey;
        $this->successCallbackUrl = $successCallbackUrl;
        $this->failCallbackUrl = $failCallbackUrl;
        $this->nonce = $nonce;
        $this->expireSeconds = $expireSeconds;
    }

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

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

    public function toArray(): array
    {
        return array_filter(call_user_func('get_object_vars', $this));
    }
}
