<?php

namespace Modules\Core\Enums;

enum RolesEnum: string
{
    case SUPER_ADMIN = 'super_admin';
    case ADMIN       = 'admin';
    case ED          = 'executive_director';
    case MANAGER     = 'manager';
    case BILLINGS    = 'billings';
    case INVENTORY   = 'inventory';
    case HR          = 'hr';
    case ACCOUNTS    = 'accounts';
    case EMPLOYEES    = 'employees';

    /**
     * Human-readable label (UI, reports, logs)
     */
    public function label(): string
    {
        return match ($this) {
            self::SUPER_ADMIN => 'Super Admin',
            self::ADMIN       => 'Admin',
            self::ED          => 'Executive Director',
            self::MANAGER     => 'Manager',
            self::BILLINGS    => 'Billings',
            self::INVENTORY   => 'Inventory',
            self::HR          => 'Human Resources',
            self::ACCOUNTS    => 'Accounts',
            self::EMPLOYEES   => 'Employees',
        };
    }

    /**
     * All role values (for validation, seeders)
     */
    public static function values(): array
    {
        return array_map(
            fn (self $role) => $role->value,
            self::cases()
        );
    }

    /**
     * Roles with full system access
     */
    public static function systemRoles(): array
    {
        return [
            self::SUPER_ADMIN->value,
            self::ADMIN->value,
        ];
    }

    /**
     * Department-level roles
     */
    public static function departmentRoles(): array
    {
        return [
            self::ED->value,
            self::MANAGER->value,
            self::BILLINGS->value,
            self::INVENTORY->value,
            self::HR->value,
            self::ACCOUNTS->value,
        ];
    }

    /**
     * Safely create enum from DB value
     */
    public static function fromValue(?string $value): ?self
    {
        return $value ? self::tryFrom($value) : null;
    }


    // Rule::in(RolesEnum::values())
    // $user->hasAnyRole(RolesEnum::systemRoles());
    // $role = RolesEnum::fromValue($user->roles->first()?->name);

    // return [
    //    'role'       => $role?->value,
    //    'role_label'=> $role?->label(),
    // ];
}
