<?php

namespace App\Console\Commands;

use App\Models\Attribute;
use App\Models\ZDevelopment;
use App\Models\ZProject;
use Illuminate\Console\Command;
use Illuminate\Support\Str;
class SetDevs extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'set:devs';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        // $pros = Attribute::where('name', 'LIKE', '%cancelled%')->get();
        // // dd(count($pros));
        // foreach ($pros as $pro) {
        //     // dd($pro);
        //     $title = str_replace("(cancelled)", "", $pro->name);
        //     $pro->name = $title;
        //     $pro->slug = Str::slug($title, '-');
        //     $pro->meta_title = $title;
        //     $pro->meta_keywords = $title;
        //     $pro->meta_desc = $title;
        //     $pro->full_desc = $title;
        //     $pro->save();
        // }
        // $devs = ZDevelopment::whereType('0')->get();
        // foreach ($devs as $dev) {
        //     $adev = Attribute::where(['type' => 'district', 'name' => $dev->commercial_title])->first();
        //     if (!$adev) {
        //         $adev = new Attribute();
        //         $adev->type = "district";
        //         $adev->name = $dev->commercial_title;
        //         $adev->slug = Str::slug($dev->commercial_title, '-');
        //         $adev->meta_title = $dev->commercial_title;
        //         $adev->meta_keywords = $dev->commercial_title;
        //         $adev->meta_desc = $dev->commercial_title;
        //         $adev->full_desc = $dev->commercial_title;
        //         $adev->save();
        //     }
        //     $devIds = $dev->getAllChildren()->unique();
        //     $pros = ZProject::whereIn('development_id', $devIds)->pluck('title')->toArray();
        //     foreach ($pros as $pro) {
        //         $apro = Attribute::where(['type' => 'project', 'name' => $pro])->first();
        //         if (!$apro) {
        //             $apro = new Attribute();
        //             $apro->parent_id = $adev->id;
        //             $apro->type = "project";
        //             $apro->name = $pro;
        //             $apro->slug = Str::slug($pro, '-');
        //             $apro->meta_title = $pro;
        //             $apro->meta_keywords = $pro;
        //             $apro->meta_desc = $pro;
        //             $apro->full_desc = $pro;
        //             $apro->save();
        //         }
        //     }
        // }
    }
}
