<?php

namespace App\Traits;

use Illuminate\Support\Facades\Redirect;

trait FlashMessageTrait
{
    /**
     * Redirect back with success message
     * 
     * @param string|array $message
     * @return \Illuminate\Http\RedirectResponse
     */
    protected function success($message)
    {
        return Redirect::back()->with('success', $message);
    }

    /**
     * Redirect back with error message
     * 
     * @param string|array $message
     * @return \Illuminate\Http\RedirectResponse
     */
    protected function error($message)
    {
        return Redirect::back()->with('error', $message);
    }

    /**
     * Redirect back with warning message
     * 
     * @param string|array $message
     * @return \Illuminate\Http\RedirectResponse
     */
    protected function warning($message)
    {
        return Redirect::back()->with('warning', $message);
    }

    /**
     * Redirect back with info message
     * 
     * @param string|array $message
     * @return \Illuminate\Http\RedirectResponse
     */
    protected function info($message)
    {
        return Redirect::back()->with('info', $message);
    }

    /**
     * Redirect to specific route with success message
     * 
     * @param string $route
     * @param string|array $message
     * @param array $parameters
     * @return \Illuminate\Http\RedirectResponse
     */
    protected function successTo($route, $message, $parameters = [])
    {
        return redirect()->route($route, $parameters)->with('success', $message);
    }

    /**
     * Redirect to specific route with error message
     * 
     * @param string $route
     * @param string|array $message
     * @param array $parameters
     * @return \Illuminate\Http\RedirectResponse
     */
    protected function errorTo($route, $message, $parameters = [])
    {
        return redirect()->route($route, $parameters)->with('error', $message);
    }
}
