<?php

namespace Database\Seeders;

use App\Models\User;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\Hash;
use App\Models\KelompokTani;
use App\Models\MemberKelompokTani;

class KelompokTaniSeeder extends Seeder
{
    public function run(): void
    {
        // 1. Buat Kelompok Tani
        $kelompok = KelompokTani::create([
            'nama' => 'Kelompok Tani Mawar',
        ]);

        // 2. Tambah Admin
        $admin = User::create([
            'name' => 'Admin Mawar',
            'username' => 'adminmawar',
            'password' => Hash::make('admin123'),
            'role' => 'admin',
        ]);

        // 3. Tambah User
        $user = User::create([
            'name' => 'User Mawar',
            'username' => 'usermawar',
            'password' => Hash::make('user123'),
            'role' => 'user',
        ]);

        // 4. Hubungkan ke member_kelompok_tani
        MemberKelompokTani::create([
            'user_id' => $admin->id,
            'kelompok_tani_id' => $kelompok->id,
            'role' => 'admin',
        ]);

        MemberKelompokTani::create([
            'user_id' => $user->id,
            'kelompok_tani_id' => $kelompok->id,
            'role' => 'user',
        ]);
    }
}
