<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class CountriesPageContent extends Model
{
    protected $fillable = ['content'];

    protected function casts(): array
    {
        return [
            'content' => 'array',
        ];
    }

    public static function defaults(): array
    {
        return [
            'seo' => [
                'title' => 'Study Abroad Destinations - ' . config('app.name'),
                'description' => 'Explore top study abroad destinations and compare opportunities for your higher education journey.',
            ],
            'hero' => [
                'eyebrow' => 'Global Opportunities',
                'title' => 'Choose Your Perfect',
                'highlight' => 'Study Destination',
                'text' => 'Compare education opportunities, visa pathways, and lifestyle fit across top countries.',
                'button' => 'Book Free Consultation',
                'image' => 'https://images.unsplash.com/photo-1607013251379-e6eecfffe234?auto=format&fit=crop&w=900&q=80',
            ],
            'listing' => [
                'title' => 'Available Countries',
                'text' => 'Browse all active destinations and open each country profile for requirements, process, and cost overview.',
                'empty_text' => 'No destinations listed yet. Check back soon.',
                'card_button' => 'Learn More',
            ],
            'trust' => [
                'title' => 'Why students compare countries with us',
                'text' => 'We help shortlist countries based on budget, profile strength, scholarship potential, and long-term goals.',
                'points' => [
                    'Clear comparison of country options',
                    'Profile-based admission strategy',
                    'Visa documentation guidance',
                ],
            ],
            'cta' => [
                'title' => 'Ready to start your journey?',
                'text' => 'Talk to our counselors and get a country shortlist tailored to your profile.',
                'button' => 'Apply Now',
                'image' => 'https://images.unsplash.com/photo-1573496359142-b8d87734a5a2?auto=format&fit=crop&w=700&q=80',
            ],
        ];
    }

    public static function getContent(): array
    {
        $row = static::query()->first();
        $stored = $row?->content ?? [];

        return array_replace_recursive(static::defaults(), $stored);
    }

    public static function saveContent(array $content): void
    {
        static::query()->updateOrCreate(
            ['id' => 1],
            ['content' => $content]
        );
    }
}
