<?php

namespace Database\Seeders;

use App\Models\Branch;
use App\Models\Category;
use App\Models\Customer;
use App\Models\Product;
use App\Models\ProductStock;
use App\Models\User;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\Hash;

class DatabaseSeeder extends Seeder
{
    use WithoutModelEvents;

    /**
     * Seed the application's database.
     */
    public function run(): void
    {
        $mainBranch = Branch::query()->create([
            'name' => 'Laundry Pusat',
            'code' => 'PST',
            'address' => 'Jl. Sudirman No. 1',
            'phone' => '021000000',
            'whatsapp_number' => '6281200000000',
        ]);

        $service = Category::query()->create(['name' => 'Laundry Kiloan', 'type' => 'service']);
        $retail = Category::query()->create(['name' => 'Retail', 'type' => 'retail']);

        User::query()->create([
            'branch_id' => $mainBranch->id,
            'name' => 'Owner Laundry',
            'email' => 'owner@laundry.test',
            'phone' => '6281111111111',
            'role' => 'owner',
            'password' => Hash::make('password'),
        ]);

        User::query()->create([
            'branch_id' => $mainBranch->id,
            'name' => 'Kasir Pusat',
            'email' => 'kasir@laundry.test',
            'phone' => '6281222222222',
            'role' => 'kasir',
            'password' => Hash::make('password'),
        ]);

        Customer::query()->create([
            'branch_id' => $mainBranch->id,
            'name' => 'Budi Santoso',
            'phone' => '6281333333333',
            'address' => 'Jakarta',
            'pin' => Hash::make('000000'),
        ]);

        $cuci = Product::query()->create([
            'category_id' => $service->id,
            'name' => 'Cuci Kering Lipat',
            'sku' => 'SRV-CKL',
            'type' => 'service',
            'unit' => 'kg',
            'price' => 8000,
            'bonus_type' => 'percent',
            'bonus_value' => 5,
        ]);

        $parfum = Product::query()->create([
            'category_id' => $retail->id,
            'name' => 'Parfum Laundry 250ml',
            'sku' => 'RTL-PARFUM',
            'type' => 'retail',
            'unit' => 'pcs',
            'price' => 25000,
            'cost_price' => 12000,
            'track_stock' => true,
            'minimum_stock' => 5,
        ]);

        ProductStock::query()->create(['branch_id' => $mainBranch->id, 'product_id' => $parfum->id, 'quantity' => 25]);
        ProductStock::query()->create(['branch_id' => $mainBranch->id, 'product_id' => $cuci->id, 'quantity' => 0]);
    }
}
