<?php

namespace App\Domains\Translation\Services;

use App\Domains\Translation\Models\Translation;
use Illuminate\Support\Facades\Redis;

class TranslationService
{
    public function set(string $locale, string $group, string $key, string $value): Translation
    {
        $translation = Translation::updateOrCreate(
            ['locale' => $locale, 'group' => $group, 'key' => $key],
            ['value' => $value, 'namespace' => '*'],
        );

        Redis::del("lang:{$locale}:{$group}");

        return $translation;
    }

    public function flushCache(string $locale, string $group): void
    {
        Redis::del("lang:{$locale}:{$group}");
    }
}
