<?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::table('accounts', function (Blueprint $table) {
            // Employee fields
            $table->enum('gender', ['male', 'female', 'other'])->nullable();
            $table->enum('employee_type', ['employee', 'worker', 'shop_manager', 'shop_employee'])->nullable();
            $table->enum('wage_type', ['salary', 'daily_wager', 'contract'])->nullable();
            $table->decimal('basic_salary', 15, 2)->nullable();
            $table->decimal('daily_wage', 15, 2)->nullable();
            $table->decimal('contract_amount', 15, 2)->nullable();
            $table->integer('working_hours')->nullable();
            $table->integer('holidays_per_week')->nullable();
            $table->boolean('allow_login')->default(false);
            $table->string('username')->nullable();
            $table->string('password')->nullable();
            $table->unsignedBigInteger('shop_id')->nullable();

            $table->unique('username');
            $table->foreign('shop_id')->references('id')->on('shops')->onDelete('set null');
        });
    }

    public function down(): void
    {
        Schema::table('accounts', function (Blueprint $table) {
            $table->dropForeign(['shop_id']);
            $table->dropUnique(['username']);
            $table->dropColumn([
                'gender', 'employee_type', 'wage_type', 'basic_salary',
                'daily_wage', 'contract_amount', 'working_hours',
                'holidays_per_week', 'allow_login', 'username',
                'password', 'shop_id'
            ]);
        });
    }
};
