<?php

namespace App\Controllers\Admin;

use App\Controllers\BaseController;
use App\Models\GeologiModel;

class Geologi extends BaseController
{
    protected $model;

    public function __construct()
    {
        $this->model = new GeologiModel();
    }

    public function index()
    {
        $data = [
            'title' => 'Geologi',
            'geologi' => $this->model->findAll()
        ];

        return view('admin/geologi', $data);
    }

    public function store()
    {
        $this->model->save([
            'jenis_geologi' => $this->request->getPost('jenis_geologi'),
            'skor'          => $this->request->getPost('skor'),
            'warna_peta'    => $this->request->getPost('warna_peta'),
        ]);

        return redirect()->to('/admin/geologi')
            ->with('success', 'Data berhasil ditambahkan');
    }

    public function update($id)
    {
        $this->model->update($id, [
            'jenis_geologi' => $this->request->getPost('jenis_geologi'),
            'skor'          => $this->request->getPost('skor'),
            'warna_peta'    => $this->request->getPost('warna_peta'),
        ]);

        return redirect()->to('/admin/geologi')
            ->with('success', 'Data berhasil diupdate');
    }

    public function delete($id)
    {
        $this->model->delete($id);

        return redirect()->to('/admin/geologi')
            ->with('success', 'Data berhasil dihapus');
    }
}
