<?php

namespace App\Domains\Real\Commands\Sync;

use Carbon\Carbon;
use Illuminate\Console\Command as BaseCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class Command extends BaseCommand
{
    protected $filename =  'sync-command.json';
    protected $initCursor = 0; // '2000-01-01 00:00:00'

    /**
     * Execute the console command.
     *
     * @param  \Symfony\Component\Console\Input\InputInterface  $input
     * @param  \Symfony\Component\Console\Output\OutputInterface  $output
     * @return mixed
     */
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $this->line('开始'.$this->description);

        begin_time_consuming();

        parent::execute($input, $output);
    }

    protected function getDateTime()
    {
        if ($month = $this->argument('month')) {
            if (!preg_match('/\d{4}-\d{1,2}/', $month)) {
                throw new \App\Exceptions\InvalidArgumentException('请输入正确的年月 #示例: 2018-10');
            }

            return Carbon::parse($month)->startOfMonth();
        }

        return Carbon::now()->startOfMonth()->subMonth();
    }

    protected function getArguments()
    {
        return [
            ['month', InputArgument::OPTIONAL, '要同步的数据月份，默认上个月  #示例: 2018-10'],
        ];
    }
}
