<?php

/**
 * Paths model for the info module.
 *
 * @package northmill-online-shared
 */
declare (strict_types=1);
namespace Northmill_Online_Shared_Checkout\Northmill_Online_Shared\Modules\Info\Models;

use Northmill_Online_Shared_Checkout\Northmill_Online_Shared\Helpers\General_Helpers;
defined('ABSPATH') || exit;
/**
 * Class Info_Paths_Model
 */
class Info_Paths_Model
{
    /**
     * The package URL, without the filename.
     * Trailing slash included.
     *
     * @var string
     */
    private string $url;
    /**
     * The absolute package path, without the filename.
     * Trailing slash included.
     *
     * @var string
     */
    private string $path;
    /**
     * The URL of to shared code.
     * With trailing slash.
     *
     * @var string
     */
    private string $shared_url;
    /**
     * The absolute path to the shared code.
     * With trailing slash.
     *
     * @var string
     */
    private string $shared_path;
    /**
     * The URL of the shared code relative to package root.
     * With trailing slash.
     *
     * @var string
     */
    private string $shared_rel_url;
    /**
     * The path to the shared code relative to package root.
     * With trailing slash.
     *
     * @var string
     */
    private string $shared_rel_path;
    /**
     * The URL to scoped shared code.
     * With trailing slash.
     *
     * @var string
     */
    private string $scoped_shared_url;
    /**
     * The path to the scoped shared code.
     * With trailing slash.
     *
     * @var string
     */
    private string $scoped_shared_path;
    /**
     * The URL of the site.
     * NO trailing slash.
     *
     * @var string
     */
    private string $site_url;
    /**
     * Info_Paths_Model constructor.
     *
     * @param string $url  The URL to the package root.
     * @param string $path The absolute path to the package root.
     */
    public function __construct(string $url, string $path)
    {
        $this->url = General_Helpers::ensure_trailing_slash($url);
        $this->path = General_Helpers::ensure_trailing_slash($path);
        $this->setup_shared_paths();
        $this->setup_site_url();
    }
    /**
     * Setup site url.
     *
     * @return void
     */
    protected function setup_site_url(): void
    {
        $this->site_url = get_site_url();
    }
    /**
     * Setup general paths for package.
     */
    protected function setup_shared_paths(): void
    {
        $this->scoped_shared_path = General_Helpers::ensure_trailing_slash(dirname(__DIR__, 2) . '/');
        $this->scoped_shared_url = $this->url . 'online-shared/';
        $this->shared_rel_path = 'vendor/northmill/online-shared/';
        $this->shared_rel_url = 'vendor/northmill/online-shared/';
        $this->shared_url = $this->url . $this->shared_rel_path;
        $this->shared_path = $this->path . $this->shared_rel_url;
    }
    /**
     * Get the package URL, without the filename.
     * Trailing slash included.
     *
     * @return string
     */
    public function get_url(): string
    {
        return $this->url;
    }
    /**
     * Get the absolute package path, without the filename.
     * Trailing slash included.
     *
     * @return string
     */
    public function get_path(): string
    {
        return $this->path;
    }
    /**
     * Get the URL to the shared code.
     * With trailing slash.
     *
     * @return string
     */
    public function get_shared_url(): string
    {
        return $this->shared_url;
    }
    /**
     * Get the absolute path to the shared code.
     * With trailing slash.
     *
     * @return string
     */
    public function get_shared_path(): string
    {
        return $this->shared_path;
    }
    /**
     * Get the URL of the shared code relative to package root.
     * With trailing slash.
     *
     * @return string
     */
    public function get_shared_rel_url(): string
    {
        return $this->shared_rel_url;
    }
    /**
     * Get the path to the shared code relative to package root.
     * With trailing slash.
     *
     * @return string
     */
    public function get_shared_rel_path(): string
    {
        return $this->shared_rel_path;
    }
    /**
     * Get the URL to scoped shared code.
     * With trailing slash.
     *
     * @return string
     */
    public function get_scoped_shared_url(): string
    {
        return $this->scoped_shared_url;
    }
    /**
     * Get the path to the scoped shared code.
     * With trailing slash.
     *
     * @return string
     */
    public function get_scoped_shared_path(): string
    {
        return $this->scoped_shared_path;
    }
    /**
     * Get the site URL.
     *
     * @return string
     */
    public function get_site_url(): string
    {
        return $this->site_url;
    }
}
