<?php

namespace Database\Seeders;

use App\Models\BlogCategory;
use App\Models\BlogPost;
use App\Models\Hotel;
use App\Models\User;
use App\Support\Tenancy;
use Illuminate\Database\Seeder;
use Illuminate\Support\Str;

class BlogSeeder extends Seeder
{
    public function run(): void
    {
        Tenancy::set(Hotel::first());

        $author = User::whereIn('role', ['admin', 'manager'])->first() ?? User::first();

        $experiences = BlogCategory::create(['name' => 'Experiences', 'slug' => 'experiences']);
        $culinary = BlogCategory::create(['name' => 'Culinary', 'slug' => 'culinary']);
        $wellness = BlogCategory::create(['name' => 'Wellness', 'slug' => 'wellness']);

        $posts = [
            [
                'category' => $culinary,
                'title' => 'Why Jollof at Epelcon Tastes Like Home',
                'excerpt' => 'Our chefs share the small rituals — the smoky base, the long simmer, the last pinch of ata rodo — that turn a familiar dish into a memory of home.',
                'meta_description' => 'The story behind Epelcon\'s Jollof rice — smoky, tomato-rich, slow-simmered by Nigerian chefs.',
                'body' => "Ask any Nigerian abroad what they miss most, and you will hear the same answer within seconds: their mother's Jollof rice. It is more than a meal — it is a Sunday afternoon, a party ending, a proof that someone loves you enough to stand over a pot for two hours.\n\nAt Epelcon, our head chef Chinedu spent a decade in Lagos kitchens before joining us. He insists on three non-negotiables. First, the tomato base is roasted, not boiled, until the sugars caramelise and the raw edge disappears. Second, the rice is parboiled and rinsed, so the grains hold their shape when the stew wraps around them. Third — and this is the one guests always ask about — the pot lid stays closed for the last twenty minutes so the base scorches gently, giving that unmistakable smoky bottom-of-the-pot flavour we call party Jollof.\n\nWe serve it with dodo (fried plantain), moin moin, and a piece of peppered chicken. On weekends, the whole restaurant smells like a wedding hall, and returning guests tell us that one bite makes them feel like their auntie is in the kitchen.\n\nIf you are visiting Abuja for the first time, or coming back after years away, order the Jollof. Bring someone you love. Take a photo, or don't — either way, you'll remember it.",
                'published_at' => now()->subDays(5),
            ],
            [
                'category' => $wellness,
                'title' => '5 Wellness Rituals to Try on Your Next Stay',
                'excerpt' => 'From sunrise stretches on the terrace to a signature ginger-lemongrass steam, here are five small rituals our returning guests build into every stay.',
                'meta_description' => 'Sunrise yoga, ginger-lemongrass steam, forest bathing — five Epelcon wellness rituals worth the trip.',
                'body' => "A great stay is not just a comfortable bed. It is a rhythm — small daily rituals that let your nervous system finally exhale. Here are five our returning guests swear by.\n\nBegin with the 6:30am terrace stretch. Fifteen minutes, unguided, just you and the sky before the city wakes up. Our concierge leaves a rolled mat by the door if you tick the box at check-in. It costs nothing and it changes the whole day.\n\nBook the ginger-lemongrass steam at least once. Twenty minutes in the eucalyptus room, followed by a cool rinse and a cup of lemongrass tea in the quiet lounge. Even skeptics come out looking ten years younger.\n\nEat one meal completely off your phone. We hold your device at the front desk if you ask — no judgement. Dinner tastes different when you have no screen to reach for.\n\nWalk the garden path at dusk. It's a fifteen-minute loop with three benches. Read a page, watch the birds, do nothing. This is our version of forest bathing.\n\nEnd the day with the four-minute breathing exercise the spa team leaves on your pillow card. In through the nose for four, hold for seven, out for eight. Three cycles. You will be asleep by the fifth.",
                'published_at' => now()->subDays(3),
            ],
            [
                'category' => $experiences,
                'title' => 'Hosting a Wedding at the Grand Ballroom: What We\'ve Learned',
                'excerpt' => 'After 200+ weddings, here are the small planning decisions that separate a beautiful day from a stressful one — from menu tastings to the golden-hour photo window.',
                'meta_description' => 'Wedding planning lessons from 200+ Epelcon Grand Ballroom celebrations — menus, timing, and guest comfort.',
                'body' => "We've hosted over two hundred weddings in the Grand Ballroom, and the patterns are impossible to unsee. The best days share a handful of quiet decisions the couple made months before the guests arrived.\n\nThey booked their menu tasting at least ten weeks out and brought two honest friends. Wedding menus are not a place for polite lies — you want the person who will tell you the fish is dry so you can pick the chicken instead.\n\nThey built a fifteen-minute buffer between every scheduled item. Weddings run late. Speeches run long. Aunties want photos. Fifteen-minute buffers absorb reality without breaking the flow.\n\nThey protected the golden-hour photo window. Our east-facing terrace is at its most flattering between 5:15 and 6:00pm depending on the season. Every couple who blocked it for portraits — even by ducking out of cocktail hour — has told us those are the photos on their walls.\n\nThey fed their vendors. It sounds obvious, but a fed photographer works twice as hard, and the DJ actually reads the room. We include a vendor meal option in every package for exactly this reason.\n\nAnd finally, they let us handle the small things. If you are getting married with us, delegate ruthlessly. Your only job that day is to be present. Everything else has a rehearsal.",
                'published_at' => now()->subDay(),
            ],
            [
                'category' => $experiences,
                'title' => 'The Story Behind Our Epelcon Circle Rewards',
                'excerpt' => 'Why we redesigned our loyalty programme from the ground up — fewer points, more moments — and how our members are using it to plan their next trip.',
                'meta_description' => 'How the new Epelcon Circle rewards programme works — earn moments, not just points, on every stay.',
                'body' => "We had a loyalty programme for years. It was fine. Points went in, points came out, most people forgot they were members. Last quarter we sat down with a hundred guests and asked a simple question: what would actually make you come back sooner? The answers were rarely about discounts.\n\nWhat guests wanted was recognition. The receptionist remembering your name. Your usual room, waiting. A birthday surprise that felt personal, not automated. So we rebuilt the programme around moments instead of points.\n\nEpelcon Circle has three tiers — Signature, Grand, and Presidential — and you move up by number of stays, not spend. That's deliberate. A guest who visits four times a year for two nights matters more to us than someone who books a single expensive weekend. Both are welcome, but our loyalty programme should reward loyalty.\n\nMembers unlock things you cannot buy: early check-in when the room is ready, a guaranteed table at the restaurant on peak nights, a curated welcome from our chefs on the third stay, and a personal concierge line from Grand tier upward. Points still exist — they buy dining credit and spa treatments — but they are no longer the point.\n\nThe first month has been quiet, in the best way. Members are booking directly instead of through third parties. Repeat visits are up. And the notes we get after a stay have changed from 'nice hotel' to 'this feels like ours.'\n\nJoin at check-in. It takes thirty seconds and your first stay counts backwards, so if you are already here reading this, you are already on your way to Grand.",
                'published_at' => now(),
            ],
        ];

        foreach ($posts as $data) {
            BlogPost::create([
                'blog_category_id' => $data['category']->id,
                'user_id' => $author?->id,
                'title' => $data['title'],
                'slug' => Str::slug($data['title']) . '-' . Str::lower(Str::random(4)),
                'excerpt' => $data['excerpt'],
                'body' => $data['body'],
                'status' => 'published',
                'published_at' => $data['published_at'],
                'meta_description' => $data['meta_description'],
                'views' => rand(45, 620),
            ]);
        }

        // A draft to show the empty-state workflow
        BlogPost::create([
            'blog_category_id' => $culinary->id,
            'user_id' => $author?->id,
            'title' => 'Behind the Bar: Building Our Signature Hibiscus Spritz (Draft)',
            'slug' => 'behind-the-bar-hibiscus-spritz-' . Str::lower(Str::random(4)),
            'excerpt' => 'Notes from the bar team as they perfect a new sundowner for the dry season.',
            'body' => "Draft in progress — the bar team is testing three variations this week.\n\nWe'll publish the final recipe once we have blind-tasted it against the current bestseller.",
            'status' => 'draft',
            'published_at' => null,
            'meta_description' => null,
            'views' => 0,
        ]);
    }
}
