<?php

namespace Database\Seeders;

use Faker\Generator;
use Illuminate\Container\Container;
use Illuminate\Database\Seeder;
use Rinvex\Categories\Models\Category;

class CategorySeeder extends Seeder
{
    /**
     * The current Faker instance.
     *
     * @var Generator
     */
    protected $faker;

    /**
     * Create a new seeder instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->faker = $this->withFaker();
    }

    /**
     * Get a new Faker instance.
     *
     * @return Generator
     */
    protected function withFaker()
    {
        return Container::getInstance()->make(Generator::class);
    }

    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {

        //Category::truncate();
        $csvFile = fopen(base_path("database/data/categories.csv"), "r");

        $firstline = true;
        while (($data = fgetcsv($csvFile, 2000, ",")) !== FALSE) {
            if (!$firstline) {

                Category::create([
                    "id"=>$data['0'],
                    "name" => [
                        "en"=>$data['1'],
                        "ar"=>$data['2'],
                    ],
                    "parent_id"=> $data['3'],
                    "verified"=>true,
                ]);
            }
            $firstline = false;
        }

        fclose($csvFile);
    }
//        Category::create([
//            'name' => [
//                'en' => 'Electrical',
//                'ar' => "كهرباء"
//            ],
//            'verified' => true
//        ]);
//        Category::create([
//            'name' => [
//                'en' => 'SW',
//                'ar' => "سوفت وير"
//            ],
//            'verified' => true
//        ]);
//        Category::create([
//            'name' => [
//                'en' => 'Communication',
//                'ar' => "اتصالات"
//            ],
//            'verified' => true
//        ]);
//
//        for ($x = 0; $x < 11; $x++) {
//            Category::create([
//                'name' => [
//                    'en' => $this->faker->company,
//                    'ar' => $this->faker->company,
//                ],
//                'description' => [
//                    'en' => $this->faker->text(50),
//                    'ar' => $this->faker->text(50),
//                ],
//                'parent_id' => null,
//                'verified' => true
//            ]);
//        }
//
//        for ($x = 1; $x < 15; $x++) {
//            for ($j = 0; $j < $this->faker->numberBetween(10, 20); $j++) {
//                Category::create([
//                    'name' => [
//                        'en' => $this->faker->company,
//                        'ar' => $this->faker->company,
//                    ],
//                    'description' => [
//                        'en' => $this->faker->text(50),
//                        'ar' => $this->faker->text(50),
//                    ],
//                    'parent_id' => $x,
//                    'verified' => true
//                ]);
//            }
//
//        }

}
