<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

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

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

    public static function defaults(): array
    {
        return [
            'hero' => [
                'title' => 'Success stories of students who made their study-abroad dreams come true',
                'highlight' => 'Success stories',
                'button' => 'Book A Free Consultation',
                'image' => 'https://images.unsplash.com/photo-1523050854058-8df90110c9f1?auto=format&fit=crop&w=1400&q=80',
            ],
            'intro' => [
                'title' => 'What Students Say About Us',
                'highlight' => 'Students',
                'text' => 'Hear from our successful students who have achieved their dreams of studying abroad.',
            ],
            'testimonials' => [
                ['initials' => 'MI', 'name' => 'Mahafuj Hossain', 'meta' => 'Charles Darwin University - Australia', 'quote' => 'I recently got my Australian student visa and I am thankful for the guidance and support I received throughout the process.'],
                ['initials' => 'AJ', 'name' => 'Ahmed Jasim', 'meta' => 'La Trobe University - Australia', 'quote' => 'The team supported me from profile review to visa submission. The process felt organized and transparent.'],
                ['initials' => 'HS', 'name' => 'Hasib Hasan Sany', 'meta' => 'Ulster University - UK', 'quote' => 'I appreciate the practical advice and quick response. Their direction made a big difference in my journey.'],
                ['initials' => 'SS', 'name' => 'Saad Ullah Sami', 'meta' => 'Charles Darwin University - Australia', 'quote' => 'From choosing the right university to visa filing, every step was handled carefully and professionally.'],
                ['initials' => 'SM', 'name' => 'Shin Mondol', 'meta' => 'Charles Darwin University - Australia', 'quote' => 'The consultants were always available and gave me confidence in every stage of the process.'],
                ['initials' => 'DC', 'name' => 'Dipesh Chandra', 'meta' => 'Ulster University - UK', 'quote' => 'Their support was practical and personalized. I was able to complete everything without confusion.'],
            ],
            'mid_cta' => [
                'title' => 'Book your free consultation today',
                'text' => "Simply send us a message and we'll handle the rest.",
                'button' => 'Book A Free Consultation',
            ],
            'featured' => [
                ['title' => 'Featured Student Story 1', 'program' => 'IT Program', 'university' => 'La Trobe University', 'country' => 'Australia', 'description' => 'He received full support from our branch and successfully started his study abroad journey.', 'image' => 'https://images.unsplash.com/photo-1542909168-82c3e7fdca5c?auto=format&fit=crop&w=900&q=80'],
                ['title' => 'Featured Student Story 2', 'program' => 'Business Program', 'university' => 'Ulster University', 'country' => 'UK', 'description' => 'From university selection to visa processing, all steps were completed with confidence.', 'image' => 'https://images.unsplash.com/photo-1521737604893-d14cc237f11d?auto=format&fit=crop&w=900&q=80'],
                ['title' => 'Featured Student Story 3', 'program' => 'Engineering Program', 'university' => 'Deakin University', 'country' => 'Australia', 'description' => 'Strong planning and documentation support helped him reach his goal faster.', 'image' => 'https://images.unsplash.com/photo-1523580846011-d3a5bc25702b?auto=format&fit=crop&w=900&q=80'],
            ],
            'videos' => [
                'title' => 'Hear From Our Students',
                'highlight' => 'Our Students',
                'text' => 'Get insights from our successful students.',
                'items' => [
                    ['title' => 'Student Review 1', 'image' => 'https://images.unsplash.com/photo-1494790108377-be9c29b29330?auto=format&fit=crop&w=700&q=80'],
                    ['title' => 'Student Review 2', 'image' => 'https://images.unsplash.com/photo-1500648767791-00dcc994a43e?auto=format&fit=crop&w=700&q=80'],
                    ['title' => 'Student Review 3', 'image' => 'https://images.unsplash.com/photo-1544005313-94ddf0286df2?auto=format&fit=crop&w=700&q=80'],
                    ['title' => 'Student Review 4', 'image' => 'https://images.unsplash.com/photo-1506794778202-cad84cf45f1d?auto=format&fit=crop&w=700&q=80'],
                ],
            ],
            'final_cta' => [
                'title' => 'Still wondering what to do?',
                'text' => 'Send us a message and let our expert counselors help you.',
                'button' => 'Book A Free Consultation',
                'image' => 'https://images.unsplash.com/photo-1573496359142-b8d87734a5a2?auto=format&fit=crop&w=700&q=80',
            ],
            'sticky_button' => 'Book A Free Consultation',
        ];
    }

    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]
        );
    }
}

