<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('user_details', function (Blueprint $table) {
            $table->id();
            $table->foreignId('user_id')->nullable()->constrained('users')->onDelete('cascade'); // ID người dùng liên kết
            $table->tinyInteger('type')->default(0)->comment('Loại tài khoản: 0-user thường, 1-công ty, 2-nhóm phát triển phần mềm, 3-freelancer');
            $table->string('phone', 20)->nullable()->comment('Số điện thoại');
            $table->string('business_email')->nullable()->comment('Email công việc');
            $table->string('company_short_name')->nullable()->comment('Tên công ty ngắn gọn');
            $table->string('company_full_name')->nullable()->comment('Tên công ty đầy đủ');
            $table->text('company_description')->nullable()->comment('Mô tả về công ty');
            $table->decimal('rating', 2, 1)->nullable()->comment('Điểm đánh giá (ví dụ 4.9)');
            $table->json('tags')->nullable()->comment('Các tag như "có thể phản hồi ngay", "chứng chỉ iso27001"');
            $table->integer('employee_count')->nullable()->comment('Số lượng nhân viên');
            $table->integer('engineer_count')->nullable()->comment('Số lượng kỹ sư');
            $table->integer('n1_japanese_count')->nullable()->comment('Số lượng người có trình độ tiếng Nhật N1');
            $table->year('established_year')->nullable()->comment('Năm thành lập');
            $table->integer('japanese_companies_performance')->nullable()->comment('Hiệu xuất với các công ty Nhật Bản (日本企業実績)');
            $table->string('company_logo')->nullable()->comment('Logo công ty');
            $table->json('strengths')->nullable()->comment('Điểm mạnh (tiêu đề và mô tả)');
            $table->string('leader_name')->nullable()->comment('Người đứng đầu');
            $table->string('leader_position')->nullable()->comment('Chức vụ người đứng đầu');
            $table->date('establishment_date')->nullable()->comment('Ngày thành lập');
            $table->decimal('charter_capital', 15, 2)->nullable()->comment('Vốn điều lệ');
            $table->decimal('estimated_value', 15, 2)->nullable()->comment('Định giá giá trị ước tính của công ty');
            $table->text('headquarters_address')->nullable()->comment('Địa chỉ trụ sở công ty');
            $table->json('branches')->nullable()->comment('Các chi nhánh');
            $table->string('article_link')->nullable()->comment('Link bài viết giới thiệu công ty');
            $table->tinyInteger('status')->default(0)->comment('Trạng thái: 0-chưa xác nhận, 1-đã xác nhận, 2-đã từ chối');
            $table->string('hourly_rate_range')->nullable()->comment('Chi phí nhân sự cho thuê (ví dụ: 350.000 - 450.000/người/tháng)');
            $table->json('key_technologies')->nullable()->comment('Các công nghệ chủ chốt (java, AWS...)');
            $table->timestamps();

            // Index cho tối ưu hiệu suất
            $table->index('user_id');
            $table->index('type');
            $table->index('status');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('user_details');
    }
};
