<?php

declare(strict_types=1);

namespace Config;

use CodeIgniter\Shield\Config\AuthGroups as ShieldAuthGroups;

class AuthGroups extends ShieldAuthGroups
{
    /**
     * --------------------------------------------------------------------
     * Default Group
     * --------------------------------------------------------------------
     * The group that a newly registered user is added to.
     */
    public string $defaultGroup = 'superadmin';

    /**
     * --------------------------------------------------------------------
     * Groups
     * --------------------------------------------------------------------
     * The available authentication systems, listed
     * with alias and class name. These can be referenced
     * by alias in the auth helper:
     *      auth('api')->attempt($credentials);
     */
    public array $groups = [
        'superadmin' => [
            'title'       => 'Super Admin',
            'description' => 'Complete control of the app.',
        ],
        'admin' => [
            'title'       => 'Admin',
            'description' => 'Approval administrators of the site.',
        ],
        'user_office' => [
            'title'       => 'User Office',
            'description' => 'Office operator users of the site.',
        ],
        'user_operator' => [
            'title'       => 'User Operator',
            'description' => 'Office operator users of the site.',
        ],
        'user_customer' => [
            'title'       => 'User Customer',
            'description' => 'General users of the site. Often customers.',
        ],
        'beta' => [
            'title'       => 'Beta User',
            'description' => 'Has access to beta-level features.',
        ],
    ];

    /**
     * --------------------------------------------------------------------
     * Permissions
     * --------------------------------------------------------------------
     * The available permissions in the system. Each system is defined
     * where the key is the
     *
     * If a permission is not listed here it cannot be used.
     */
    public array $permissions = [
        'all_agen.access' => 'Can access all agent',
        'all_agen.create' => 'Can create all agent',
        'all_agen.edit' => 'Can edit all agent',
        'all_agen.delete' => 'Can delete all agent',
        'all_agen.approval' => 'Can approve agent',

        'self_agen.access' => '-',
        'self_agen.create' => '-',
        'self_agen.edit' => '-',
        'self_agen.delete' => '-',

        'all_pangkalan.access' => '-',
        'all_pangkalan.create' => '-',
        'all_pangkalan.edit' => '-',
        'all_pangkalan.delete' => '-',
        'all_pangkalan.approve' => '-',

        'all_pengajuan_pangkalan.access' => '-',
        'all_pengajuan_pangkalan.create' => '-',
        'all_pengajuan_pangkalan.edit' => '-',
        'all_pengajuan_pangkalan.delete' => '-',
        'all_pengajuan_pangkalan.kirim' => '-',
        'all_pengajuan_pangkalan.approve' => '-',

        'all_pengajuan_pangkalan_komentar.access' => '-',
        'all_pengajuan_pangkalan_komentar.create' => '-',
        'all_pengajuan_pangkalan_komentar.edit' => '-',
        'all_pengajuan_pangkalan_komentar.delete' => '-',

        'all_pengajuan_perubahan_pangkalan.access' => '-',
        'all_pengajuan_perubahan_pangkalan.create' => '-',
        'all_pengajuan_perubahan_pangkalan.delete' => '-',
        'all_pengajuan_perubahan_pangkalan.kirim' => '-',
        'all_pengajuan_perubahan_pangkalan.approve' => '-',

        'all_pengajuan_perubahan_pangkalan_komentar.access' => '-',
        'all_pengajuan_perubahan_pangkalan_komentar.create' => '-',
        'all_pengajuan_perubahan_pangkalan_komentar.delete' => '-',

        'agen_pangkalan.access' => '-',
        'agen_pangkalan.create' => '-',
        'agen_pangkalan.edit' => '-',
        'agen_pangkalan.delete' => '-',

        'agen_pengajuan_pangkalan.access' => '-',
        'agen_pengajuan_pangkalan.create' => '-',
        'agen_pengajuan_pangkalan.edit' => '-',
        'agen_pengajuan_pangkalan.delete' => '-',
        'agen_pengajuan_pangkalan.kirim' => '-',

        'agen_pengajuan_pangkalan_komentar.access' => '-',
        'agen_pengajuan_pangkalan_komentar.create' => '-',
        'agen_pengajuan_pangkalan_komentar.delete' => '-',

        'agen_pengajuan_perubahan_pangkalan.access' => '-',
        'agen_pengajuan_perubahan_pangkalan.create' => '-',
        'agen_pengajuan_perubahan_pangkalan.edit' => '-',
        'agen_pengajuan_perubahan_pangkalan.delete' => '-',
        'agen_pengajuan_perubahan_pangkalan.kirim' => '-',

        'agen_pengajuan_perubahan_pangkalan_komentar.access' => '-',
        'agen_pengajuan_perubahan_pangkalan_komentar.create' => '-',
        'agen_pengajuan_perubahan_pangkalan_komentar.delete' => '-',

        'admin_notif_access' => '-',
        'agen_notif_access' => '-',

        'super_admin_stats_access' => '',
        'all_stats_access' => '',
        'self_stats_access' => '',

        'admin_user_access' => '-',
        'admin_user_create' => '-',
        'admin_user_edit' => '-',
        'admin_user_delete' => '-',
        
        'agen_user_access' => '-',
        'agen_user_create' => '-',
        'agen_user_edit' => '-',
        'agen_user_delete' => '-',

        'admin.access'        => 'Can access the sites admin area',
        'admin.settings'      => 'Can access the main site settings',

        'users.access' => 'Can manage other admins',
        'users.create'        => 'Can create new non-admin users',
        'users.edit'          => 'Can edit existing non-admin users',
        'users.delete'        => 'Can delete existing non-admin users',

        'beta.access'         => 'Can access beta-level features',
    ];

    /**
     * --------------------------------------------------------------------
     * Permissions Matrix
     * --------------------------------------------------------------------
     * Maps permissions to groups.
     */
    public array $matrix = [
        'superadmin' => [
            'all_agen.*',
            'all_pangkalan.*',
            'all_pengajuan_pangkalan.*',
            'all_pengajuan_perubahan_pangkalan.*',
            'admin_notif_access',
            'admin.*',
            'users.*',
        ],

        'admin' => [
            'all_agen.access',
            'all_pangkalan.access',
            'all_pengajuan_pangkalan.access',
            'all_pengajuan_pangkalan.approve',
            'all_pengajuan_pangkalan_komentar.access',
            'all_pengajuan_pangkalan_komentar.create',
            'all_pengajuan_pangkalan_komentar.delete',

            'all_pengajuan_perubahan_pangkalan.access',
            'all_pengajuan_perubahan_pangkalan.approve',
            'all_pengajuan_perubahan_pangkalan_komentar.access',
            'all_pengajuan_perubahan_pangkalan_komentar.create',
            'all_pengajuan_perubahan_pangkalan_komentar.delete',

            'admin_user.access',
            'admin_user.edit',
            'users.*',
        ],

        'user_office' => [
            'allagen.*',
            'users.*',
        ],
        'user_operator' => [
            
        ],
        'user_customer' => [
            'self_agen.access',
            'agen_pangkalan.access',
            'agen_pengajuan_pangkalan.access',
            'agen_pengajuan_pangkalan.create',
            'agen_pengajuan_pangkalan.edit',
            'agen_pengajuan_pangkalan.delete',

            'agen_pengajuan_pangkalan.kirim',
            
            'agen_pengajuan_pangkalan_komentar.access',

            'agen_pengajuan_perubahan_pangkalan.access',
            'agen_pengajuan_perubahan_pangkalan.create',
            'agen_pengajuan_perubahan_pangkalan.edit',
            'agen_pengajuan_perubahan_pangkalan.delete',

            'agen_pengajuan_perubahan_pangkalan.kirim',

            'agen_pengajuan_perubahan_pangkalan_komentar.access',
            'agen_user_access',
            'agen_user_edit'
        ],

        'developer' => [
            'admin.access',
            'admin.settings',
            'users.create',
            'users.edit',
            'beta.access',
        ],
        'user' => [],
        'beta' => [
            'beta.access',
        ],
    ];
}
