<?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('users', function (Blueprint $table) {
            $table->id();
            $table->foreignId('store_id')->constrained()->comment('所属门店');
            $table->unsignedBigInteger('department_id')->nullable();
            $table->unsignedBigInteger('position_id')->nullable();
            $table->string('username', 50)->unique()->comment('登录名');
            $table->string('password', 255);
            $table->string('name', 50)->comment('真实姓名');
            $table->string('phone', 20)->nullable();
            $table->string('email', 100)->nullable();
            $table->string('avatar', 255)->nullable();
            $table->tinyInteger('status')->default(1)->comment('0待审核 1正常 2禁用');
            $table->tinyInteger('is_super')->default(0)->comment('1超级管理员');
            $table->timestamp('last_login_at')->nullable();
            $table->timestamps();
            $table->softDeletes();

            $table->index('store_id');
            $table->index('phone');
        });
    }

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