<?php

namespace WPDesk\FakturyKSEF\Services;

use WPDesk\FakturyKSEF\Api\Environments\AbstractEnvironment;

class KSeFPreviewURLService {

	private AbstractEnvironment $environment;

	private string $vat_number;

	public function __construct( string $vat_number, AbstractEnvironment $environment ) {
		$this->environment = $environment;
		$this->vat_number  = $vat_number;
	}

	public function get_invoice_preview_url( string $date, string $verification_key ): string {
		$base_url         = $this->environment->get_host_url();
		$verification_key = rtrim( strtr( $verification_key, '+/', '-_' ), '=' );
		$path             = sprintf( '/client-app/invoice/%s/%s/%s', $this->vat_number, $date, $verification_key );

		return $base_url . $path;
	}
}
