<?php

namespace Database\Factories;

use App\Models\OrderManagement\BillingDesk;
use App\Models\StockManagement\Warehouse;
use App\Models\StockManagement\WareHouseType;
use Illuminate\Database\Eloquent\Factories\Factory;

/**
 * @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Product>
 */
class WarehouseFactory extends Factory{
    protected $model = Warehouse::class;

    public function definition(){
        return [
            'name'          => fake()->sentence(2, true),
//            'slug'          => fake()->unique()->slug(2, true),
            'code'          => fake()->unique()->slug(2, true),
//            'active'        => true,
        ];
    }


    public function isStore(): Factory{
        return $this->state(function (array $attributes) {
            return [
                'warehouse_type_code' => WareHouseType::STORE,
                'is_bad_goods' => rand(1,0),
            ];
        });
    }

    public function isPointOfSales(): Factory{
        return $this->state(function (array $attributes) {
            $stores = Warehouse::stores()->get();

            $store = filled($stores) ? $stores->random() : Warehouse::factory()->isStore()->create();
            return [
                'warehouse_type_code' => WareHouseType::POINT_OF_SALE,
                'store_id' => $store->getKey(),
            ];
        });
    }
}
