<?php

use Illuminate\Database\Seeder;
use App\BrandModelOld;
use App\Brand;
use App\BrandModel;
use App\Helpers\Helper;

class CloneBrandModelData extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        $list = BrandModelOld::all();
        foreach ($list as $item) {
            $brandSlug = Helper::slug($item->brand->slug);
            $cBrand = Brand::where('slug', $brandSlug)->first();
            if (!isset($cBrand)) {
                $cBrand = Brand::create([
                    'name'         => $item->brand->name,
                    'slug'         => $brandSlug,
                    'description'  => $item->brand->description,
                    'is_activated' => 1,
                    'is_deleted'   => 0,
                    'created_at'   => date('Y-m-d H:i:s'),
                    'updated_at'   => date('Y-m-d H:i:s'),
                ]);
                print "Created Brand: " . $item->brand->name . " -- " . $cBrand->id . "\r\n";
            }
            $checkBModel = BrandModel::where('name', $item->name)->where('brand_id', $cBrand->id)->count();
            if ($checkBModel <= 0) {
                $bModel = BrandModel::create([
                    'brand_id'     => $cBrand->id,
                    'name'         => $item->name,
                    'description'  => $item->description,
                    'is_activated' => 1,
                    'is_deleted'   => 0,
                    'created_at'   => date('Y-m-d H:i:s'),
                    'updated_at'   => date('Y-m-d H:i:s'),
                ]);
                print "Created Brand Model: " . $bModel->name . " -- " . $bModel->id . "\r\n";
            }
        }
    }
}
