<?php

declare(strict_types=1);

namespace App\Repositories;

final class TypeClientRepository extends BaseRepository
{
    public function allActive(): array
    {
        return $this->fetchAll("SELECT * FROM types_clients WHERE actif = 1 ORDER BY libelle ASC");
    }

    public function all(): array
    {
        return $this->fetchAll("SELECT * FROM types_clients ORDER BY actif DESC, libelle ASC");
    }

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

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

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