<?php

namespace App\Controllers;

use App\Models\Notification;

class NotificationController extends AdminController
{
    public function __construct()
    {
        parent::__construct();
    }

    public function getNotification()
    {
        $Notification = new Notification();

        $notifications = $Notification->getNotifications();

        return $this->response->setJSON($notifications);
    }

    public function markAsRead(int $id)
    {
        $Notification = new Notification();
        $Notification->markAsRead($id);

        return $this->response->setJSON(['status' => 'success']);
    }

    public function createNotification(string $message, string $group, ?int $store_id, ?string $link)
    {
        $Notification = new Notification();

        $data = [
            'message' => $message,
            'is_read'    => 0,
            'forgroup' => $group,
            'store_id' => $store_id,
            'link' => $link,
            'created_at' => date('Y-m-d H:i:s')
        ];

        $Notification->insertNotification($data);
    }
}
