<?php

namespace App\Installer\Services;

use Illuminate\Http\Request;

/**
 * Domain Resolver Service
 * Handles domain detection and resolution
 */
class DomainResolver
{
    public function __construct(
        private Request $request
    ) {}

    /**
     * Get installation domain
     */
    public function getInstallationDomain(): string
    {
        $domain = $this->request->getHost();

        // Remove www. prefix
        $domain = preg_replace('/^www\./', '', $domain);

        return $domain;
    }

    /**
     * Get full installation URL
     */
    public function getInstallationUrl(): string
    {
        return $this->request->getSchemeAndHttpHost();
    }

    /**
     * Get installation IP address
     */
    public function getInstallationIp(): ?string
    {
        return $this->request->ip();
    }
}
