<?php

namespace Database\Seeders;

use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\Hash;
use App\Models\User;
use App\Models\Customer;
use App\Models\Invoice;
use App\Models\InvoiceItem;
use Carbon\Carbon;

class DatabaseSeeder extends Seeder
{
    public function run()
    {
        // Admin User
        User::create([
            'name' => 'Admin',
            'email' => 'admin@riyasrisilks.com',
            'password' => Hash::make('password'),
        ]);

        // Customers
        $customer1 = Customer::create([
            'customer_name' => 'Rahul Sharma',
            'mobile' => '9876543210',
            'address1' => '12/4, Main Road',
            'city' => 'Salem',
            'state' => 'Tamil Nadu',
            'pincode' => '636001',
            'gst_number' => '33ABCDE1234F1Z5'
        ]);

        $customer2 = Customer::create([
            'customer_name' => 'Priya Kumar',
            'mobile' => '8765432109',
            'address1' => '45, Cross Street',
            'city' => 'Erode',
            'state' => 'Tamil Nadu',
            'pincode' => '638001',
        ]);

        // Invoices
        $invoice1 = Invoice::create([
            'invoice_no' => 'INV000001',
            'invoice_date' => Carbon::now()->subDays(2),
            'customer_id' => $customer1->id,
            'subtotal' => 5000,
            'discount' => 500,
            'grand_total' => 4500,
        ]);

        InvoiceItem::create([
            'invoice_id' => $invoice1->id,
            'product_name' => 'Kanchipuram Silk Saree',
            'qty' => 1,
            'rate' => 3000,
            'amount' => 3000,
        ]);

        InvoiceItem::create([
            'invoice_id' => $invoice1->id,
            'product_name' => 'Designer Saree',
            'qty' => 1,
            'rate' => 2000,
            'amount' => 2000,
        ]);

        $invoice2 = Invoice::create([
            'invoice_no' => 'INV000002',
            'invoice_date' => Carbon::now(),
            'customer_id' => $customer2->id,
            'subtotal' => 15000,
            'discount' => 1000,
            'grand_total' => 14000,
        ]);

        InvoiceItem::create([
            'invoice_id' => $invoice2->id,
            'product_name' => 'Bridal Silk Saree',
            'qty' => 2,
            'rate' => 7500,
            'amount' => 15000,
        ]);
    }
}
