<?php

namespace Database\Seeders;

use App\Models\Company;
use App\Models\Customer;
use App\Models\TaxRate;
use App\Models\Vendor;
use Illuminate\Database\Seeder;

class DatabaseSeeder extends Seeder
{
    public function run(): void
    {
        $this->call([
            AdminUserSeeder::class,
            MeasurementUnitSeeder::class,
        ]);

        $company = Company::create([
            'name' => 'Demo Trading Co.',
            'legal_name' => 'Demo Trading Company Pvt Ltd',
            'email' => 'info@demotrading.com',
            'phone' => '9876543210',
            'gstin' => '27AAAAA0000A1Z5',
            'address' => '123 Business Park, MG Road',
            'city' => 'Mumbai',
            'state' => 'Maharashtra',
            'pincode' => '400001',
            'currency' => 'INR',
            'invoice_prefix' => 'INV',
            'invoice_start_number' => 1001,
        ]);

        $taxRates = [
            ['name' => 'GST 0%', 'rate' => 0, 'type' => 'gst'],
            ['name' => 'GST 5%', 'rate' => 5, 'type' => 'gst'],
            ['name' => 'GST 12%', 'rate' => 12, 'type' => 'gst'],
            ['name' => 'GST 18%', 'rate' => 18, 'type' => 'gst'],
            ['name' => 'GST 28%', 'rate' => 28, 'type' => 'gst'],
        ];

        foreach ($taxRates as $tax) {
            TaxRate::create(array_merge($tax, ['company_id' => $company->id]));
        }

        Customer::create([
            'company_id' => $company->id,
            'name' => 'ABC Retailers',
            'contact_person' => 'Rahul Sharma',
            'email' => 'rahul@abcretail.com',
            'phone' => '9988776655',
            'gstin' => '27BBBBB0000B1Z5',
            'billing_address' => 'Shop 12, Market Road',
            'city' => 'Pune',
            'state' => 'Maharashtra',
            'opening_balance' => 0,
        ]);

        Vendor::create([
            'company_id' => $company->id,
            'name' => 'Prime Suppliers',
            'contact_person' => 'Amit Patel',
            'email' => 'amit@primesuppliers.com',
            'phone' => '9123456780',
            'gstin' => '27CCCCC0000C1Z5',
            'address' => 'Warehouse 5, Industrial Area',
            'city' => 'Mumbai',
            'state' => 'Maharashtra',
            'opening_balance' => 0,
        ]);
    }
}
