<?php

namespace App\Models;

use App\Core\Model;

class IdentitasModel extends Model
{
    protected string $table = 'identitas_kampus';

    public function getIdentitas(): array
    {
        $stmt = $this->db->query("SELECT * FROM {$this->table} LIMIT 1");
        $data = $stmt->fetch();

        return $data ?: [];
    }

    /**
     * Simpan identitas kampus. Karena tabel ini hanya berisi 1 baris,
     * otomatis insert kalau belum ada data, atau update kalau sudah ada.
     */
    public function save(array $data): void
    {
        $existing = $this->getIdentitas();

        if ($existing) {
            $this->update((int) $existing['id'], $data);
        } else {
            $this->insert($data);
        }
    }
}
