<?php

namespace App\Models;

use Core\Database;

class SoalPMBModel
{
    private $pdo;

    public function __construct()
    {
        $this->pdo = Database::getConnection();
    }

    public function soalExists(string $pertanyaanNorm): bool
    {
        $sql = "SELECT COUNT(*) FROM tb_soal_testpmb WHERE LOWER(TRIM(pertanyaan)) = :pertanyaan";
        $stmt = $this->pdo->prepare($sql);
        $stmt->execute(['pertanyaan' => $pertanyaanNorm]);
        $count = $stmt->fetchColumn();
        return $count > 0;
    }

    public function insertSoal($pertanyaan, $a, $b, $c, $d, $e, $jawaban, $status): bool
    {
        $sql = "INSERT INTO tb_soal_testpmb (pertanyaan, pilihan_a, pilihan_b, pilihan_c, pilihan_d, pilihan_e, jawaban, status) 
                VALUES (:pertanyaan, :a, :b, :c, :d, :e, :jawaban, :status)";
        $stmt = $this->pdo->prepare($sql);
        return $stmt->execute([
            ':pertanyaan' => $pertanyaan,
            ':a' => $a,
            ':b' => $b,
            ':c' => $c,
            ':d' => $d,
            ':e' => $e,
            ':jawaban' => $jawaban,
            ':status' => $status,
        ]);
    }
}
