<?php

namespace App\Libs\Services;

use App\Models\InfoBoxFile;

class InfoBoxFileService
{
    public function getInfoBox($data) {
        $infoBox = InfoBoxFile::first();

        if (empty($infoBox)) {
            return null;
        }

        return [
            'infoBox' => $infoBox,
        ];
    }

    public function createOrUpdate($data)
    {
        $infoBox = InfoBoxFile::first();

        if ($infoBox) {
            $infoBox->html_content = $data['htmlContent'];
            $infoBox->save();
        } else {
            $infoBox = InfoBoxFile::create([
                'html_content' => $data['htmlContent']
            ]);
        }

        return $infoBox;
    }

    public function deleteInfoBox($data)
    {
        $infoBox = InfoBoxFile::first();
        if ($infoBox) {
            $infoBox->delete();
        }

        return [
            'message' => 'success',
        ];
    }
}
