<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateSplitBandHrv extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'table:band_hrvs';

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

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        $month = date('m');
        $year = date("Y");
        if ($month == 12) {//下一年
            $year += 1;
            $month = 1;
        }else {
            $month += 1;
        }
        $month = str_pad($month, 2, '0', STR_PAD_LEFT);
        $table_name = "band_hrvs_{$year}{$month}";
        if (!Schema::hasTable($table_name)) {
            Schema::create($table_name, function (Blueprint $table) {
                $table->id();
                $table->integer('user_id')->unsigned()->comment("用户id");
                $table->integer('band_id')->unsigned()->comment("手环id");
                $table->timestamp('date')->nullable()->comment("时间");
                $table->integer('highBP')->comment("高压");
                $table->integer('stress')->unsigned()->comment("压力");
                $table->integer('lowBP')->unsigned()->comment("低压");
                $table->integer('heartRate')->unsigned()->comment("心率");
                $table->integer('hrv')->unsigned()->comment("血管老化度");
                $table->integer('vascularAging')->unsigned()->comment("血管老化度");
                $table->timestamps();
                $table->unique(['user_id', 'band_id', 'date']);
            });
        }


        return Command::SUCCESS;
    }
}
