<?php

namespace App\Domains\FiestaFutbolInfantil\Services;

use App\Domains\Catalog\Models\Category;
use App\Domains\FiestaFutbolInfantil\Enums\FiestaCategory;
use App\Domains\Tenant\Models\Tenant;

class CategoryVisibilityService
{
    public function isEnabled(Tenant $tenant, FiestaCategory $category): bool
    {
        return Category::query()
            ->where('tenant_code', $tenant->codigo)
            ->where('nombre', $category->categoryName())
            ->value('is_enabled') ?? true;
    }

    public function update(Tenant $tenant, FiestaCategory $category, bool $isEnabled): Category
    {
        $model = Category::query()->firstOrCreate([
            'tenant_code' => $tenant->codigo,
            'nombre' => $category->categoryName(),
        ]);
        $model->update(['is_enabled' => $isEnabled]);

        return $model;
    }
}
