<?php

namespace Database\Seeders;

use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
use Carbon\Carbon;

class TransaksiSeeder extends Seeder
{
    public function run(): void
    {
        $tahunIni = date('Y'); 

        // ==========================================
        // TRANSAKSI 1: BULAN JANUARI (Selesai)
        // ==========================================
        $trx1 = DB::table('transaksis')->insertGetId([
            'kode_invoice'      => 'INV-' . $tahunIni . '01-001',
            'pembeli_id'        => 1, 
            'petani_id'         => 1, 
            'tanggal_transaksi' => Carbon::create($tahunIni, 1, 15, 10, 0, 0),
            'alamat_pengiriman' => 'Jl. Raya Nganjuk No. 123, Jawa Timur',
            'total_harga'       => 250000,
            'status'            => 'selesai',
            'created_at'        => Carbon::create($tahunIni, 1, 15, 10, 0, 0),
            'updated_at'        => Carbon::create($tahunIni, 1, 15, 10, 0, 0),
        ]);

        DB::table('detail_transaksis')->insert([
            'transaksi_id' => $trx1,
            'produk_id'    => 1, 
            'jumlah'       => 5,
            'harga_satuan' => 50000,
            'subtotal'     => 250000,
            'created_at'   => Carbon::create($tahunIni, 1, 15, 10, 0, 0),
            'updated_at'   => Carbon::create($tahunIni, 1, 15, 10, 0, 0),
        ]);

        // ==========================================
        // TRANSAKSI 2: BULAN FEBRUARI (Selesai)
        // ==========================================
        $trx2 = DB::table('transaksis')->insertGetId([
            'kode_invoice'      => 'INV-' . $tahunIni . '02-002',
            'pembeli_id'        => 1,
            'petani_id'         => 1,
            'tanggal_transaksi' => Carbon::create($tahunIni, 2, 10, 14, 30, 0),
            'alamat_pengiriman' => 'Jl. Sudirman No. 45, Jakarta',
            'total_harga'       => 400000,
            'status'            => 'selesai',
            'created_at'        => Carbon::create($tahunIni, 2, 10, 14, 30, 0),
            'updated_at'        => Carbon::create($tahunIni, 2, 10, 14, 30, 0),
        ]);

        DB::table('detail_transaksis')->insert([
            'transaksi_id' => $trx2,
            'produk_id'    => 1,
            'jumlah'       => 8,
            'harga_satuan' => 50000,
            'subtotal'     => 400000,
            'created_at'   => Carbon::create($tahunIni, 2, 10, 14, 30, 0),
            'updated_at'   => Carbon::create($tahunIni, 2, 10, 14, 30, 0),
        ]);

        // ==========================================
        // TRANSAKSI 3: BULAN MARET (Selesai)
        // ==========================================
        $trx3 = DB::table('transaksis')->insertGetId([
            'kode_invoice'      => 'INV-' . $tahunIni . '03-003',
            'pembeli_id'        => 1,
            'petani_id'         => 1,
            'tanggal_transaksi' => Carbon::create($tahunIni, 1, 5, 9, 15, 0),
            'alamat_pengiriman' => 'Perumahan Indah Blok C2, Surabaya',
            'total_harga'       => 150000,
            'status'            => 'selesai',
            'created_at'        => Carbon::create($tahunIni, 3, 5, 9, 15, 0),
            'updated_at'        => Carbon::create($tahunIni, 3, 5, 9, 15, 0),
        ]);

        DB::table('detail_transaksis')->insert([
            'transaksi_id' => $trx3,
            'produk_id'    => 1,
            'jumlah'       => 3,
            'harga_satuan' => 50000,
            'subtotal'     => 150000,
            'created_at'   => Carbon::create($tahunIni, 3, 5, 9, 15, 0),
            'updated_at'   => Carbon::create($tahunIni, 3, 5, 9, 15, 0),
        ]);
    }
}