<?php

namespace Config;

use CodeIgniter\Config\Filters as BaseFilters;
use CodeIgniter\Filters\CSRF;
use CodeIgniter\Filters\DebugToolbar;
use CodeIgniter\Filters\Honeypot;
use CodeIgniter\Filters\InvalidChars;
use CodeIgniter\Filters\SecureHeaders;

class Filters extends BaseFilters
{
    /**
     * Filter aliases.
     */
    public array $aliases = [
        'csrf'          => CSRF::class,
        'toolbar'       => DebugToolbar::class,
        'honeypot'      => Honeypot::class,
        'invalidchars'  => InvalidChars::class,
        'secureheaders' => SecureHeaders::class,

// Custom filter login
        'auth'          => \App\Filters\AuthFilter::class,
        'role'          => \App\Filters\RoleFilter::class,
    ];

    /**
     * Method filters.
     */
    public array $methods = [];

    /**
     * Global filters.
     */
    public array $filters = [
        'auth' => [
            'before' => [
                'dashboard',
                'katalog*',
                'buku*',
                'ruang_baca*',
                'anggota*',
                'peminjaman*',
                'pengembalian*',
                'pengunjung*',
                'laporan*',
                'pengaturan*',
            ],
        ],
        // Hanya petugas
        'role:petugas' => [
            'before' => [
                'dashboard',
                'buku*',
                'anggota*',
                'peminjaman*',
                'pengembalian*',
                'pengunjung*',
                'laporan*',
                'pengaturan*',
                // Kelola ruang baca khusus petugas
                'ruang_baca',
                'ruang_baca/create',
                'ruang_baca/store',
                'ruang_baca/edit/*',
                'ruang_baca/update/*',
                'ruang_baca/delete/*',
            ],
        ],
        // Guru & siswa hanya katalog
        'role:guru,siswa' => [
            'before' => [
                'katalog*',
            ],
        ],
    ];

    /**
     * Required filters.
     */
    public array $required = [
        'before' => [
            'csrf',
        ],
        'after' => [
            'toolbar',
        ],
    ];
}
