<?php

namespace App\Services;

class MetaService
{
    protected $title;
    protected $description;
    protected $image;
    protected $url;
    protected $type = 'website';
    protected $siteName;

    public function __construct()
    {
        $this->siteName = config('app.name');
        $this->url = request()->url();
    }

    public function setTitle($title)
    {
        $this->title = $title;
        return $this;
    }

    public function setDescription($description)
    {
        $this->description = $description;
        return $this;
    }

    public function setImage($image)
    {
        $this->image = $image;
        return $this;
    }

    public function setUrl($url)
    {
        $this->url = $url;
        return $this;
    }

    public function setType($type)
    {
        $this->type = $type;
        return $this;
    }

    public function render()
    {
        $title = $this->title ? $this->title . ' - ' . $this->siteName : $this->siteName;
        $description = $this->description ?? setting('meta_description', 'AI Mental Wellness Platform');
        $image = $this->image ?? asset('images/og-default.jpg');

        $html = '';
        $html .= "<title>{$title}</title>\n";
        $html .= "<meta name=\"description\" content=\"{$description}\">\n";
        $html .= "<meta property=\"og:title\" content=\"{$title}\">\n";
        $html .= "<meta property=\"og:description\" content=\"{$description}\">\n";
        $html .= "<meta property=\"og:image\" content=\"{$image}\">\n";
        $html .= "<meta property=\"og:url\" content=\"{$this->url}\">\n";
        $html .= "<meta property=\"og:type\" content=\"{$this->type}\">\n";
        $html .= "<meta property=\"og:site_name\" content=\"{$this->siteName}\">\n";
        $html .= "<meta name=\"twitter:card\" content=\"summary_large_image\">\n";
        $html .= "<meta name=\"twitter:title\" content=\"{$title}\">\n";
        $html .= "<meta name=\"twitter:description\" content=\"{$description}\">\n";
        $html .= "<meta name=\"twitter:image\" content=\"{$image}\">\n";

        return $html;
    }
}
