<?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('md_absensi', function (Blueprint $table) {
            $table->id();
            $table->foreignId('user_id')->constrained('md_user')->onDelete('cascade');
            $table->date('tanggal');
            
            // Status Absen (Hadir, WFH, Izin, Sakit)
            $table->string('status', 50)->default('hadir');
            
            // Bukti Foto / Kamera
            $table->string('foto', 255)->nullable();
            $table->string('foto_kamera', 255)->nullable();
            
            // Lokasi (WFO & WFH Check-in/Check-out)
            $table->decimal('lokasi_latitude', 10, 8)->nullable();
            $table->decimal('lokasi_longitude', 11, 8)->nullable();
            $table->decimal('lokasi_akurasi', 8, 2)->nullable();
            $table->timestamp('lokasi_diambil_pada')->nullable();
            
            $table->decimal('checkout_lokasi_latitude', 10, 8)->nullable();
            $table->decimal('checkout_lokasi_longitude', 11, 8)->nullable();
            $table->decimal('checkout_lokasi_akurasi', 8, 2)->nullable();
            
            // Laporan
            $table->text('laporan')->nullable();
            
            $table->timestamps();
            
            $table->unique(['user_id', 'tanggal']);
        });
    }

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