<?php

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

return new class extends Migration
{
    protected $connection = 'sam_stat';

    public function up(): void
    {
        Schema::connection($this->connection)->create('dim_date', function (Blueprint $table) {
            $table->date('date_key')->primary()->comment('날짜 키');
            $table->smallInteger('year')->comment('연도');
            $table->tinyInteger('quarter')->comment('분기 (1~4)');
            $table->tinyInteger('month')->comment('월');
            $table->tinyInteger('week')->comment('ISO 주차');
            $table->tinyInteger('day_of_week')->comment('요일 (1:월~7:일)');
            $table->tinyInteger('day_of_month')->comment('일');
            $table->boolean('is_weekend')->comment('주말 여부');
            $table->boolean('is_holiday')->default(false)->comment('공휴일 여부');
            $table->string('holiday_name', 100)->nullable()->comment('공휴일명');
            $table->smallInteger('fiscal_year')->nullable()->comment('회계연도');
            $table->tinyInteger('fiscal_quarter')->nullable()->comment('회계분기');
        });
    }

    public function down(): void
    {
        Schema::connection($this->connection)->dropIfExists('dim_date');
    }
};
