<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Models\NoticeBoard;
use Illuminate\Http\Request;
use App\Constants\Status;

class NoticeBoardController extends Controller
{
    // public function editCreate($id = 0)
    // {
    //     $pageTitle = $id ? 'Notice Update' : 'Notice Create';
    //     $notice = new NoticeBoard();
    //     if ($id) {
    //         $notice = NoticeBoard::findOrFail($id);
    //     }
    //     return view('admin.noticeBoard.edit', compact('notice', 'pageTitle'));
    // }

    public function updateStore(Request $request, $id )
    {
        $request->validate([
            'body' => 'required|string',
            'status' => 'required|in:' . implode(',', [Status::ENABLE, Status::DISABLE]),
        ]);

            $notice = NoticeBoard::find($id);
            $notice->body = $request->body;
            $notice->status = $request->status;
            $notice->save();

        $notify[] = ['success', 'Notice ' . ($id ? 'updated' : 'created') . ' successfully'];
        return back()->withNotify($notify);
    }
    public function index(Request $request)
    {
        $pageTitle = 'Notice Board';
        $emptyMessage = 'No Notice found';
        $notice =  NoticeBoard::first();
        return view('admin.noticeBoard.index', compact('pageTitle', 'emptyMessage', 'notice'));
    }
}
