<?php
namespace Bookaro\Service;

defined( 'ABSPATH' ) || exit;

use Bookaro\Contracts\PaymentsGatewayInterface;

/**
 * No-op payments gateway for Lite builds.
 */
class NullPaymentsGateway implements PaymentsGatewayInterface
{
    public function is_available(): bool
    {
        return false;
    }

    public function get_payment_mode(): string
    {
        return 'pay_later';
    }

    public function create_order( int $booking_id, array $data )
    {
        return new \WP_Error(
            'bookaro_pro_required',
            __( 'Available in MyBookaro Pro.', 'mybookaro' )
        );
    }

    public function sync_booking_order( int $order_id, string $booking_date, ?string $booking_date_to ): void
    {
        // No-op in Lite.
    }

    public function is_booking_paid( \Bookaro\Entity\Booking $booking ): bool
    {
        return true;
    }

    public function get_currency_settings(): array
    {
        return [
            'symbol'             => '$',
            'format'             => '%1$s%2$s',
            'decimals'           => 2,
            'decimal_separator'  => '.',
            'thousand_separator' => ',',
        ];
    }

    public function format_price( float $amount ): string
    {
        $settings = $this->get_currency_settings();
        $decimals = (int) ( $settings['decimals'] ?? 2 );
        $dec_sep  = (string) ( $settings['decimal_separator'] ?? '.' );
        $thou_sep = (string) ( $settings['thousand_separator'] ?? ',' );
        $symbol   = (string) ( $settings['symbol'] ?? '' );
        $format   = (string) ( $settings['format'] ?? '%1$s%2$s' );

        $number = number_format( $amount, $decimals, $dec_sep, $thou_sep );
        return sprintf( $format, $symbol, $number );
    }

    public function get_order_status_options(): array
    {
        return [
            'pending'    => __( 'Pending payment', 'mybookaro' ),
            'on-hold'    => __( 'On hold', 'mybookaro' ),
            'processing' => __( 'Processing', 'mybookaro' ),
            'completed'  => __( 'Completed', 'mybookaro' ),
            'cancelled'  => __( 'Cancelled', 'mybookaro' ),
            'refunded'   => __( 'Refunded', 'mybookaro' ),
            'failed'     => __( 'Failed', 'mybookaro' ),
        ];
    }
}
