<?php

namespace App\Console\Commands\ChannelManager;

use App\Core\Mail\LogMail;
use App\Core\Service\PropertyRoomRatePriceService;
use App\Core\Service\PropertyRoomService;
use App\Exceptions\ApiErrorException;
use Carbon\Carbon;
use GuzzleHttp\Client;
use Illuminate\Console\Command;
use Illuminate\Mail\Mailer;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use Maatwebsite\Excel\Facades\Excel;
use PhpOffice\PhpSpreadsheet\IOFactory;

class PropertyBookingSyncService extends Command
{
    protected $signature = 'cron:propertybooking-sync-service';

    protected $description = '';
    protected $mailer;

    public function __construct(
        Mailer $mailer,
        PropertyRoomService $propertyRoomService,
        PropertyRoomRatePriceService $propertyRoomRatePriceService
    )
    {
        parent::__construct();
        $this->mailer = $mailer;
        $this->propertyRoomService = $propertyRoomService;
        $this->propertyRoomRatePriceService = $propertyRoomRatePriceService;
    }

    public function handle()
    {

        $sourcePath = 'C:\www\api.extranetwork.com\app\Console\Commands\ChannelManager\akgun.xlsx';


        $reader = new \PhpOffice\PhpSpreadsheet\Reader\Xlsx();
        $spreadsheet = $reader->load($sourcePath);
        $sheet = $spreadsheet->getSheet($spreadsheet->getFirstSheetIndex());
        $rows = $sheet->toArray();

        $rowKey = 0;
        foreach ($rows as $row) {

            $rowKey++;

            if($rowKey < 3) {
                continue;
            }

            dd($row);
        }

        //dd(file_exists($sourcePath));

        $this->info(date('Y-m-d H:i:s') . ' : Start');



        $this->info(date('Y-m-d H:i:s') . ' : Finished');


    }
}
