<?php

declare(strict_types=1);

namespace App\Repositories;

final class MarqueArticleRepository extends BaseRepository
{
    public function all(): array
    {
        return $this->fetchAll(
            "SELECT *
             FROM marques_articles
             ORDER BY actif DESC, libelle ASC"
        );
    }

    public function create(string $libelle): void
    {
        $this->execute(
            "INSERT INTO marques_articles (libelle, actif)
             VALUES (:libelle, 1)",
            [
                'libelle' => trim($libelle),
            ]
        );
    }

    public function update(int $id, string $libelle, int $actif): void
    {
        $this->execute(
            "UPDATE marques_articles
             SET libelle = :libelle,
                 actif = :actif
             WHERE id = :id",
            [
                'id' => $id,
                'libelle' => trim($libelle),
                'actif' => $actif,
            ]
        );
    }

    public function deactivate(int $id): void
    {
        $this->execute(
            "UPDATE marques_articles
             SET actif = 0
             WHERE id = :id",
            [
                'id' => $id,
            ]
        );
    }
}