<?php

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

class CreateRespondenAndJawabanSurveiTables extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        // Tabel responden untuk menyimpan data pelapor
        Schema::create('responden', function (Blueprint $table) {
            $table->id();
            $table->string('nama_pelapor', 100);
            $table->string('no_hp', 15);
            $table->string('email', 100)->nullable();
            $table->text('alamat')->nullable();
            $table->date('tanggal_survei');
            $table->text('saran')->nullable();
            $table->timestamps();
        });

        // Tabel jawaban_survei untuk menyimpan jawaban per unsur
        Schema::create('jawaban_survei', function (Blueprint $table) {
            $table->id();
            $table->foreignId('responden_id')->constrained('responden')->onDelete('cascade');
            $table->integer('unsur_id'); // 1-11 untuk unsur pertanyaan
            $table->integer('nilai'); // 1-4 untuk nilai jawaban
            $table->timestamps();

            $table->index(['responden_id', 'unsur_id']);
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('jawaban_survei');
        Schema::dropIfExists('responden');
    }
}
