<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    public function up(): void
    {
        Schema::create('sms_counts', function (Blueprint $table): void {
            $table->id();
            $table->integer('user_id');
            $table->string('month', 7)->default('');
            $table->string('operator_name', 64)->default('');
            $table->string('operator_number', 32)->default('');
            $table->tinyInteger('sim_slot')->default(-1);
            $table->unsignedTinyInteger('type')->default(1);
            $table->unsignedBigInteger('total_request')->default(0);
            $table->unsignedBigInteger('total_sent')->default(0);
            $table->unsignedBigInteger('total_failed')->default(0);
            $table->timestamp('last_update')->nullable();
            $table->timestamps();

            $table->unique(
                ['user_id', 'month', 'operator_name', 'operator_number', 'sim_slot', 'type'],
                'sms_counts_user_month_op_num_slot_type_unique'
            );
            $table->index(['user_id', 'month', 'last_update'], 'sms_counts_user_month_last_update_idx');
        });
    }

    public function down(): void
    {
        Schema::dropIfExists('sms_counts');
    }
};
