<?php

namespace App\Http\Controllers;

use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Support\Facades\Auth;

abstract class Controller
{
    use AuthorizesRequests;

    /**
     * Get the role-based dashboard route for the authenticated user
     */
    protected function getDashboardRoute(): string
    {
        $user = Auth::user();

        if ($user && $user->role) {
            $roleSlug = $user->role->slug;

            // Super Admin and Admin users go to admin dashboard
            if (in_array($roleSlug, ['super-admin', 'admin'])) {
                return route('admin.dashboard', absolute: false);
            }

            // Customer users go to customer dashboard
            if ($roleSlug === 'customer') {
                return route('customer.dashboard', absolute: false);
            }
        }

        // Default fallback to admin dashboard if no role or unknown role
        return route('admin.dashboard', absolute: false);
    }
}
