<?php

namespace App\Http\Controllers\Admin;

use App\Contact;
use App\Http\Controllers\Controller;
use App\Notify;

/**
 * Class SettingController
 *
 * @package App\Http\Controllers
 */
class NotifyController extends Controller
{
    public function all()
    {
        $notifyCount = Notify::where('is_check', false)->count();
        $notifyTop = Notify::select('*')->orderBy('created_at', 'DESC')->paginate(15);
        $contactCount = Contact::where('is_read', false)->where('is_deleted', false)->count();

        return response()->json(['data' => [
            'all'     => $notifyCount,
            'contact' => $contactCount,
            'list'    => $notifyTop
        ]], 200);
    }

    public function update()
    {
        Notify::where('is_check', false)->update(['is_check' => 1]);
        return response()->json(null, 204);
    }

    public function mark($id = 0)
    {
        Notify::where('id', $id)->update(['is_check' => 1, 'is_read' => 1]);
        $notifyTop = Notify::select('*')->orderBy('created_at', 'DESC')->paginate(15);

        return response()->json(['data' => ['list' => $notifyTop]], 200);
    }

    public function destroy()
    {
        Notify::truncate();
        $notifyTop = Notify::select('*')->orderBy('created_at', 'DESC')->paginate(15);

        return response()->json(['data' => [
            'all'     => 0,
            'contact' => 0,
            'list'    => $notifyTop
        ]], 200);
    }
}
