<?php

namespace App\Console\Commands;

use App\Models\Attribute;
use App\Models\Listing;
use App\Models\ZListing;
use App\Models\ZTermMeta;
use App\Models\ZTermRelation;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;
class SetListing extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'set:listing';

    /**
     * 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()
    {
        
        // $olisting = ZListing::where(['post_type' => 'property', 'post_status' => 'publish'])->get();
        // foreach ($olisting as $ol) {
        // $listing = Listing::where('ref_id', $ol->ID)->first();
        // if ($ol->baths) {
        // $attr = Attribute::where(['type' => 'location', 'name' => $ol->loc_adr->meta_value])->first();
        // if (!$attr) {
        //     $attr = new Attribute();
        //     $attr->type = "location";
        //     $attr->name = $ol->loc_adr->meta_value;
        //     $attr->slug = Str::slug($ol->loc_adr->meta_value, '-');
        //     $attr->meta_title = $ol->loc_adr->meta_value;
        //     $attr->meta_keywords = $ol->loc_adr->meta_value;
        //     $attr->meta_desc = $ol->loc_adr->meta_value;
        //     $attr->save();
        // }
        // $listing->location_id = $attr->id;
        // $listing->save();



        // $earea = explode("-",$ol->baths->meta_value);
        // $listing->baths = $earea[0];
        // $listing->max_baths = $earea[1];
        // $listing->save();
        // }
        // }
        // $rels = ZTermRelation::all();
        // foreach ($rels as $rel) {
        //     $listing = Listing::where('ref_id', $rel->object_id)->first();
        //     if ($listing) {
        //         $attr = Attribute::where('ref_id', $rel->term_taxonomy_id)->first();
        //         if ($attr) {
        //             $listing->features = $listing->features ? $listing->features . ',' . $attr->id : $attr->id;
        //             $listing->save();
        //         }
        //     }
        // }
    }

    public function formatPrice($price)
    {
        if (strpos($price, '.') !== false) {
            $price = round((float) $price);
        }
        return $price;
    }
}
