<?php

namespace App\Http\Controllers;

use App\Models\MarketingDone;
use Brian2694\Toastr\Facades\Toastr;
use Illuminate\Http\Request;

class MarketingStatusController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        //
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        $marketingStatuses = MarketingDone::all();

        return view('marketingStatus.create', compact('marketingStatuses'));
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        $validated = $request->validate([
            'name' => 'required',
            'status' => 'required',
            ]);
            
            // dd($request->all());
        // Create a new Marketing Status
        $marketingStatus = new MarketingDone();
        $marketingStatus->name = $request->name;
        $marketingStatus->status = $request->status;
        $marketingStatus->save();

        Toastr::success('Marketing Status added successfully.', 'Success');
        return redirect()->route('marketingstatus.create');
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        $marketingStatus = MarketingDone::findOrFail($id);
        return view('marketingStatus.edit', compact('marketingStatus'));
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        $validated = $request->validate([
            'name' => 'required',
            'status' => 'required',
            ]);
            
        // Find the existing Marketing Status
        $marketingStatus = MarketingDone::findOrFail($id);
        $marketingStatus->name = $request->name;
        $marketingStatus->status = $request->status;
        $marketingStatus->save();

        Toastr::success('Marketing Status updated successfully.', 'Success');
        return redirect()->route('marketingstatus.create');
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    }
}
