<?php

namespace Twnt4All\Engine\Support;

class TwintReply extends JsonReply
{
    public function enroll_response( $status, $error )
    {
        $this->status( $status )->message( $error );
        return $this;
    }

    public function message( $message )
    {
        $this->add_attribute( 'message', $message );
        return $this;
    }

    public function order_uuid( $order_uuid )
    {
        $this->add_attribute( 'order_uuid', $order_uuid );
        return $this;
    }

    public function redirect_url( $redirect_url )
    {
        $this->add_attribute( 'redirect_url', $redirect_url );
        return $this;
    }

    public function reason( $reason )
    {
        $this->add_attribute( 'reason', $reason );
        return $this;
    }

    public function respond()
    {
        ob_clean();
        if ( ! headers_sent() ) {
            header( 'Content-Type: application/json; charset=utf-8' );
        }
        // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- JSON payload, not HTML ; consumed by JavaScript, not rendered as markup.
        echo wp_json_encode( $this->response );
        exit;
    }
}