<?php

namespace Database\Seeders;

use Illuminate\Database\Seeder;
use App\Models\User; 
use App\Models\Category;
use App\Models\Event;
use App\Models\Transaction;
use App\Models\Partner;
use Illuminate\Support\Facades\Hash;

class DatabaseSeeder extends Seeder
{
    /**
     * Seed the application's database.
     */
    public function run(): void
    {
        // 1. User Admin (Menggunakan updateOrCreate agar bebas error duplicate entry)
        $admin = User::updateOrCreate(
            ['email' => 'admin@amikom.ac.id'],
            [
                'name' => 'Admin Amikom',
                'password' => bcrypt('password'),
                'role' => 'admin',
            ]
        );

        // 2. Partner / Penyelenggara (dengan akun login)
        $partnerUser1 = User::updateOrCreate(
            ['email' => 'abp@productions.com'],
            [
                'name' => 'ABP Productions',
                'password' => Hash::make('password'),
                'role' => 'partner',
            ]
        );

        $partner1 = Partner::updateOrCreate(
            ['email' => 'abp@productions.com'],
            [
                'user_id' => $partnerUser1->id,
                'name' => 'ABP Productions',
                'phone' => '081234567890',
                'description' => 'Penyelenggara event musik dan festival profesional.',
                'status' => 'active',
                'logo_url' => null,
            ]
        );

        $partnerUser2 = User::updateOrCreate(
            ['email' => 'techevent@indonesia.com'],
            [
                'name' => 'TechEvent Indonesia',
                'password' => Hash::make('password'),
                'role' => 'partner',
            ]
        );

        $partner2 = Partner::updateOrCreate(
            ['email' => 'techevent@indonesia.com'],
            [
                'user_id' => $partnerUser2->id,
                'name' => 'TechEvent Indonesia',
                'phone' => '081234567891',
                'description' => 'Penyelenggara seminar dan workshop teknologi.',
                'status' => 'active',
                'logo_url' => null,
            ]
        );

        $partnerUser3 = User::updateOrCreate(
            ['email' => 'kreativa@studio.com'],
            [
                'name' => 'Kreativa Studio',
                'password' => Hash::make('password'),
                'role' => 'partner',
            ]
        );

        $partner3 = Partner::updateOrCreate(
            ['email' => 'kreativa@studio.com'],
            [
                'user_id' => $partnerUser3->id,
                'name' => 'Kreativa Studio',
                'phone' => '081234567892',
                'description' => 'Studio kreatif yang menyelenggarakan event seni dan kompetisi.',
                'status' => 'pending',
                'logo_url' => null,
            ]
        );

        // 3. Kategori
        $kategori1 = Category::updateOrCreate(
            ['slug' => 'seminar-it'],
            ['name' => 'Seminar IT']
        );

        $kategori2 = Category::updateOrCreate(
            ['slug' => 'entertainment'],
            ['name' => 'Entertainment']
        );

        $kategori3 = Category::updateOrCreate(
            ['slug' => 'bisnis'],
            ['name' => 'Bisnis']
        );

        // 4. Event
        $event1 = Event::updateOrCreate(
            ['title' => 'UI/UX Masterclass'],
            [
                'category_id' => $kategori1->id,
                'partner_id' => $partner2->id,
                'description' => 'Belajar desain UI/UX dari dasar hingga mahir.',
                'date' => '2026-05-01 10:00:00',
                'location' => 'Lab Komputer',
                'price' => 50000,
                'stock' => 100,
                'poster_path' => 'posters/event-1.png',
            ]
        );

        $event2 = Event::updateOrCreate(
            ['title' => 'Web Development Bootcamp'],
            [
                'category_id' => $kategori1->id,
                'partner_id' => $partner2->id,
                'description' => 'Pelatihan membuat website modern.',
                'date' => '2026-05-02 10:00:00',
                'location' => 'Lab Programming',
                'price' => 50000,
                'stock' => 100,
                'poster_path' => 'posters/event-2.png',
            ]
        );

        $event3 = Event::updateOrCreate(
            ['title' => 'E-Sport U-Champ'],
            [
                'category_id' => $kategori2->id,
                'partner_id' => $partner3->id,
                'description' => 'Turnamen e-sport antar mahasiswa.',
                'date' => '2026-05-03 10:00:00',
                'location' => 'Auditorium',
                'price' => 50000,
                'stock' => 100,
                'poster_path' => 'posters/event-3.png',
            ]
        );

        Event::updateOrCreate(
            ['title' => 'Music Festival'],
            [
                'category_id' => $kategori2->id,
                'partner_id' => $partner1->id,
                'description' => 'Festival musik meriah dengan berbagai band.',
                'date' => '2026-05-04 18:00:00',
                'location' => 'Lapangan Kampus',
                'price' => 50000,
                'stock' => 100,
                'poster_path' => 'posters/event-4.png',
            ]
        );

        Event::updateOrCreate(
            ['title' => 'Digital Marketing Seminar'],
            [
                'category_id' => $kategori3->id,
                'partner_id' => $partner1->id,
                'description' => 'Strategi marketing di era digital.',
                'date' => '2026-05-05 13:00:00',
                'location' => 'Ruang Seminar',
                'price' => 50000,
                'stock' => 100,
                'poster_path' => 'posters/event-5.png',
            ]
        );

        Event::updateOrCreate(
            ['title' => 'Startup Pitching Day'],
            [
                'category_id' => $kategori3->id,
                'partner_id' => $partner3->id,
                'description' => 'Presentasi ide bisnis startup.',
                'date' => '2026-05-06 13:00:00',
                'location' => 'Inkubator Bisnis',
                'price' => 50000,
                'stock' => 100,
                'poster_path' => 'posters/event-6.png',
            ]
        );

        // 5. Transaksi
        Transaction::updateOrCreate(
            ['order_id' => 'TRX-99210'],
            [
                'event_id' => $event1->id,
                'customer_name' => 'Donni Prabowo',
                'customer_email' => 'donni.prabowo@gmail.com',
                'customer_phone' => '081234567890',
                'total_price' => 50000,
                'status' => 'success',
                'snap_token' => null,
            ]
        );

        Transaction::updateOrCreate(
            ['order_id' => 'TRX-99211'],
            [
                'event_id' => $event2->id,
                'customer_name' => 'Ragisha Hanny',
                'customer_email' => 'ragisha@amikom.ac.id',
                'customer_phone' => '089876543210',
                'total_price' => 50000,
                'status' => 'success',
                'snap_token' => null,
            ]
        );

        Transaction::updateOrCreate(
            ['order_id' => 'TRX-99212'],
            [
                'event_id' => $event3->id,
                'customer_name' => 'Budi Setiawan',
                'customer_email' => 'budi@gmail.com',
                'customer_phone' => '085612345678',
                'total_price' => 50000,
                'status' => 'pending',
                'snap_token' => null,
            ]
        );
    } 
}

