<?php

namespace Database\Seeders;


use Illuminate\Database\Seeder;
use App\Models\NotificationSetting;
use Dipokhalder\EnvEditor\EnvEditor;
use Dipokhalder\Settings\Facades\Settings;


class NotificationTableSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        $envService = new EnvEditor();
        Settings::group('notification')->set([
            'notification_fcm_public_vapid_key'    => $envService->getValue('DEMO') ? 'BAl01QSTtjXvHrcCaTLLHAKaVhwVzRtIA6ZrQcCwEyI5pbS8Fx_O7hxwwMrW-pc3tNhcROUrcqQ0biR91GFyiqM' : '',
            'notification_fcm_api_key'             => $envService->getValue('DEMO') ? 'AIzaSyBXCMHPTYkbjU1m3-DdHoBUto0uuwgzxP4' : '',
            'notification_fcm_auth_domain'         => $envService->getValue('DEMO') ? 'tiffinking-1e561.firebaseapp.com' : '',
            'notification_fcm_project_id'          => $envService->getValue('DEMO') ? 'tiffinking-1e561' : '',
            'notification_fcm_storage_bucket'      => $envService->getValue('DEMO') ? 'tiffinking-1e561.firebasestorage.app' : '',
            'notification_fcm_messaging_sender_id' => $envService->getValue('DEMO') ? '260991804052' : '',
            'notification_fcm_app_id'              => $envService->getValue('DEMO') ? '1:260991804052:web:14ad8bba6a48168f5fca81' : '',
            'notification_fcm_measurement_id'      => $envService->getValue('DEMO') ? 'G-TPMN439PME' : '',
            'notification_fcm_json_file'           => '',
        ]);

        if ($envService->getValue('DEMO') && file_exists(public_path('/file/service-account-file.json'))) {
            $setting = NotificationSetting::where('key', 'notification_fcm_json_file')->first();
            $setting->addMedia(public_path('/file/service-account-file.json'))->preservingOriginal()->usingFileName('service-account-file.json')->toMediaCollection('notification-file');
        }
    }
}
