<?php

namespace Database\Seeders;

use App\Models\Event;
use App\Models\Faq;
use App\Models\News;
use App\Models\Page;
use App\Models\User;
use Illuminate\Database\Seeder;
use Illuminate\Support\Carbon;

/**
 * Public website content, seeded from what King Ceasor University currently
 * publishes on kcu.ac.ug (PRD 28, 52).
 */
class CmsSeeder extends Seeder
{
    public function run(): void
    {
        $author = User::query()->whereHas('roles', fn ($q) => $q->where('slug', 'super-administrator'))->first();

        $this->pages($author?->id);
        $this->news($author?->id);
        $this->events();
        $this->faqs();

        $this->command?->info(sprintf(
            'Seeded %d pages, %d news articles, %d events and %d FAQs.',
            Page::count(), News::count(), Event::count(), Faq::count(),
        ));
    }

    protected function pages(?int $authorId): void
    {
        $pages = [
            [
                'title' => 'About King Ceasor University',
                'slug' => 'about',
                'excerpt' => 'A Chartered institution committed to excellence in education, research, innovation, and service to society.',
                'content' => <<<'HTML'
<p>King Ceasor University is a Chartered private institution based in Kampala, Uganda, established in 2011 and accredited by the Uganda National Council for Higher Education. The University takes its motto, <em>Veritas</em> — truth — as the standard for its teaching, research and service.</p>

<p>KCU has built a reputation for innovative, comprehensive and relevant programmes across healthcare science, law, management, computing and the earth sciences. Its Bachelor of Medicine and Bachelor of Surgery programme has achieved recognition through ECFMG pathways, expanding the international opportunities available to graduates.</p>

<h2>Our Vision</h2>
<p>To be a centre of academic excellence that transforms lives, advances knowledge and prepares globally competitive professionals and leaders.</p>

<h2>Our Mission</h2>
<p>To provide a supportive and intellectually stimulating environment that encourages critical thinking, ethical conduct, innovation and academic excellence, and to serve society through research, partnership and practice.</p>

<h2>Our Values</h2>
<ul>
    <li><strong>Truth</strong> — intellectual honesty in scholarship and conduct</li>
    <li><strong>Excellence</strong> — the highest standard in teaching, learning and service</li>
    <li><strong>Innovation</strong> — curiosity applied to real problems</li>
    <li><strong>Integrity</strong> — ethical practice in every discipline</li>
    <li><strong>Service</strong> — knowledge in the service of community and nation</li>
</ul>

<h2>Our Campuses</h2>
<p>KCU is a multi-campus university. The main campus sits on Bunga Hill along Ggaba Road in Makindye Division, Kampala. Clinical training is delivered at the Mulago Campus adjacent to Mulago National Referral Hospital, with further campuses at Namugongo in Wakiso District and Kisoro in south-western Uganda.</p>
HTML,
                'seo_description' => 'King Ceasor University is a Chartered private university in Kampala, Uganda, established in 2011 and accredited by the NCHE.',
            ],
            [
                'title' => "Vice Chancellor's Message",
                'slug' => 'vice-chancellors-message',
                'excerpt' => 'Welcome to King Ceasor University, a Chartered institution committed to excellence in education, research, innovation, and service to society.',
                'content' => <<<'HTML'
<p>Welcome to King Ceasor University, a Chartered institution committed to excellence in education, research, innovation, and service to society.</p>

<p>At KCU, we believe education is transformative, empowering learners with the knowledge, skills, values, and leadership qualities needed to thrive in a rapidly changing world. We provide a supportive and intellectually stimulating environment that encourages critical thinking, ethical conduct, innovation, and academic excellence.</p>

<p>The award of our University Charter reflects our commitment to quality higher education and continuous institutional growth. We are also proud that our Bachelor of Medicine and Bachelor of Surgery (MBChB) programme has achieved recognition through ECFMG pathways, expanding international opportunities for our graduates.</p>

<p>As we look ahead, we are embracing Competency-Based Education and Training (CBET), advancing research and innovation, strengthening global partnerships, and leveraging technology to enhance learning.</p>

<p>I invite you to join KCU as we transform lives, advance knowledge, and prepare globally competitive professionals and leaders for the future.</p>

<p><strong>Dr. Charity Basaza Mulenga</strong><br>Vice Chancellor, King Ceasor University</p>
HTML,
                'seo_description' => "A message from Dr. Charity Basaza Mulenga, Vice Chancellor of King Ceasor University.",
            ],
            [
                'title' => 'Student Life',
                'slug' => 'student-life',
                'excerpt' => 'Support services, clubs, leadership, learning resources and campus life at KCU.',
                'content' => <<<'HTML'
<p>Life at King Ceasor University extends well beyond the lecture theatre. Students join a community with active guilds, sports, faith groups, professional societies and volunteering programmes across all four campuses.</p>

<h2>Support Services</h2>
<p>Academic advising, counselling, careers guidance and disability support are available to every registered student. Our student affairs team helps new students settle in during orientation week and stays available throughout the year.</p>

<h2>Learning Resources</h2>
<p>The University library provides an online catalogue, study spaces and access to electronic journals. K-Class, our virtual learning environment, hosts course materials and supports blended delivery.</p>

<h2>Clubs and Leadership</h2>
<p>Students lead moot court competitions, cybersecurity clubs, health outreach camps, debate societies and entrepreneurship groups — many of which represent KCU at national events.</p>
HTML,
                'seo_description' => 'Explore support services, clubs, leadership, learning resources and campus life at King Ceasor University.',
            ],
            [
                'title' => 'Research & Innovation',
                'slug' => 'research',
                'excerpt' => 'Advancing research, innovation and global partnerships.',
                'content' => <<<'HTML'
<p>Research at King Ceasor University is directed at problems that matter to Uganda and the region: health systems and clinical practice, cybersecurity and digital forensics, energy and the extractive industries, and law and governance.</p>

<h2>Global Partnerships</h2>
<p>KCU collaborates with institutions across Africa, Europe, Asia and the Americas, including the University of Fort Hare (South Africa), Aleksandër Moisiu University Durrës (Albania), Universidad de Montevideo (Uruguay), the Arab Academy for Science, Technology &amp; Maritime Transport (Egypt), Superior University (Pakistan), Rosebank International University College (Ghana) and the Erasmus+ Programme of the European Union.</p>

<h2>Clinical and National Partners</h2>
<p>Clinical training and health research are delivered in partnership with Mulago National Referral Hospital and Kiruddu National Referral Hospital. The University also works with Makerere University and the Research and Education Network for Uganda (RENU).</p>
HTML,
                'seo_description' => 'Research, innovation and global partnerships at King Ceasor University.',
            ],
            [
                'title' => 'Contact Us',
                'slug' => 'contact',
                'excerpt' => 'Get in touch with King Ceasor University.',
                'content' => <<<'HTML'
<p>We are happy to answer questions about programmes, admissions and campus life.</p>
<p><strong>Main Campus:</strong> Plot 32 Ggaba Road, Bunga Hill, Kampala, Uganda<br>
<strong>Telephone:</strong> +256 200 911 450 / +256 394 716 326<br>
<strong>General enquiries:</strong> info@kcu.ac.ug<br>
<strong>Admissions:</strong> admissions@kcu.ac.ug</p>
HTML,
                'seo_description' => 'Contact King Ceasor University, Plot 32 Ggaba Road, Bunga Hill, Kampala.',
            ],
        ];

        foreach ($pages as $page) {
            Page::updateOrCreate(['slug' => $page['slug']], $page + [
                'status' => 'published',
                'published_at' => now(),
                'created_by' => $authorId,
                'updated_by' => $authorId,
            ]);
        }
    }

    protected function news(?int $authorId): void
    {
        $articles = [
            [
                'title' => "King Ceasor University Participates in Uganda's Inaugural National Cybersecurity Conference",
                'slug' => 'kcu-national-cybersecurity-conference',
                'category' => 'Partnerships',
                'excerpt' => "King Ceasor University participated in Uganda's inaugural National Cybersecurity Conference at the Sheraton Kampala Hotel.",
                'content' => <<<'HTML'
<p>King Ceasor University participated in Uganda's inaugural National Cybersecurity Conference at the Sheraton Kampala Hotel, represented by Vice Chancellor Dr Charity Basaza Mulenga, Dr. Habiba N. Ngugi and Assoc. Prof. Annabella H. Ejiri.</p>

<p>The conference brought together government, industry and academia to address the country's growing exposure to cyber threats and the skills needed to meet them. KCU's participation reflects the University's investment in security-led computing through its Bachelor of Science in Computer Forensics.</p>

<p>Delegates discussed national capacity building, incident response coordination and the role of universities in producing graduates equipped for digital investigation and defence.</p>
HTML,
                'published_at' => Carbon::create(2026, 8, 11, 9, 0),
            ],
            [
                'title' => 'KCU MBChB Programme Recognised Through ECFMG Pathways',
                'slug' => 'mbchb-ecfmg-recognition',
                'category' => 'Academics',
                'excerpt' => "The University's Bachelor of Medicine and Bachelor of Surgery programme has achieved recognition through ECFMG pathways.",
                'content' => <<<'HTML'
<p>King Ceasor University's Bachelor of Medicine and Bachelor of Surgery (MBChB) programme has achieved recognition through ECFMG pathways, expanding the international opportunities available to graduates.</p>

<p>The recognition means KCU medical graduates can pursue certification routes that open postgraduate training and practice opportunities beyond Uganda, while continuing to serve the national health system.</p>

<p>"This reflects our commitment to quality higher education and continuous institutional growth," said Vice Chancellor Dr. Charity Basaza Mulenga.</p>
HTML,
                'published_at' => Carbon::create(2026, 6, 24, 10, 30),
            ],
            [
                'title' => 'August Intake Now Open Across All Schools',
                'slug' => 'august-intake-open',
                'category' => 'Admissions',
                'excerpt' => 'Applications are open for undergraduate, diploma and certificate programmes in the August intake.',
                'content' => <<<'HTML'
<p>King Ceasor University is accepting applications for the August intake across the School of Medicine, Health &amp; Life Sciences, the School of Law &amp; Management Sciences, and the School of Science, Computing &amp; Engineering.</p>

<p>Applicants can create an account, complete the application online, upload their academic documents, pay the application fee and track progress through to a decision — all from a phone or computer.</p>

<p>Applications close at the end of September. Early application is encouraged, particularly for programmes with limited clinical placement capacity.</p>
HTML,
                'published_at' => Carbon::create(2026, 4, 2, 8, 0),
            ],
        ];

        foreach ($articles as $article) {
            News::updateOrCreate(['slug' => $article['slug']], $article + [
                'status' => 'published',
                'author_id' => $authorId,
            ]);
        }
    }

    protected function events(): void
    {
        $events = [
            [
                'title' => '6th Graduation Ceremony',
                'slug' => 'sixth-graduation-ceremony',
                'excerpt' => 'King Ceasor University celebrates the class of 2026.',
                'description' => '<p>The University community gathers to confer awards on graduands across all three schools. Celebrating Excellence.</p>',
                'location' => 'Main Campus, Bunga Hill, Kampala',
                'starts_at' => Carbon::create(2026, 7, 3, 9, 0),
                'ends_at' => Carbon::create(2026, 7, 3, 15, 0),
            ],
            [
                'title' => 'August Intake Application Deadline',
                'slug' => 'august-intake-deadline',
                'excerpt' => 'Final day to submit applications for the August intake.',
                'description' => '<p>All applications for the August intake must be submitted, paid for and complete by 23:59 on this date.</p>',
                'location' => 'Online',
                'starts_at' => Carbon::create((int) now()->year, 9, 30, 23, 59),
            ],
            [
                'title' => 'Open Day: Meet the Schools',
                'slug' => 'open-day-meet-the-schools',
                'excerpt' => 'Tour the campus, meet academic staff and explore programmes.',
                'description' => '<p>Prospective students and parents are invited to the Bunga campus to meet faculty from all three schools, tour teaching facilities and speak with the admissions team.</p>',
                'location' => 'Main Campus, Bunga Hill, Kampala',
                'starts_at' => Carbon::create((int) now()->year, 9, 12, 9, 0),
                'ends_at' => Carbon::create((int) now()->year, 9, 12, 16, 0),
            ],
        ];

        foreach ($events as $event) {
            Event::updateOrCreate(['slug' => $event['slug']], $event + ['status' => 'published']);
        }
    }

    protected function faqs(): void
    {
        $faqs = [
            ['How do I apply to King Ceasor University?', 'Create an applicant account, complete the online application, upload your academic documents, pay the application fee and submit. You can save and return at any time.', 'Admissions'],
            ['What is the application fee?', 'The standard application fee is UGX 50,000. Some professional programmes, including the MBChB, carry a higher fee which is shown before you pay.', 'Admissions'],
            ['Which documents do I need?', 'You will need your academic certificates and transcripts, a passport photograph and a copy of your national ID or passport. Additional documents may be requested during review.', 'Documents'],
            ['Can I apply for more than one programme?', 'Yes. You may list up to three programme choices in order of preference on a single application.', 'Admissions'],
            ['How will I know the outcome of my application?', 'You can track your application status in your applicant portal at any time, and we will email you whenever the status changes.', 'Admissions'],
            ['How do I pay the application fee?', 'Applications can be paid by bank deposit using the reference shown on your payment page. Mobile money will be enabled for the current intake.', 'Payments'],
            ['Where are the KCU campuses?', 'The main campus is on Bunga Hill, Plot 32 Ggaba Road in Kampala. Clinical programmes are taught at the Mulago campus, with further campuses at Namugongo and Kisoro.', 'General'],
        ];

        foreach ($faqs as $order => [$question, $answer, $category]) {
            Faq::updateOrCreate(['question' => $question], [
                'answer' => $answer,
                'category' => $category,
                'status' => 'published',
                'sort_order' => $order + 1,
            ]);
        }
    }
}
