<?php

declare(strict_types=1);

namespace App\Modules\Administration\Repositories;

use System\Database\QueryBuilder;

final class EmployeeFamilyRepository
{
    public function __construct(
        private QueryBuilder $query
    ) {
    }

    public function byEmployee(
        int $employeeId
    ): array {
        return $this->query
            ->table('employee_family')
            ->where(
                'employee_id',
                $employeeId
            )
            ->orderBy(
                'id',
                'ASC'
            )
            ->get();
    }

    public function find(
        int $id
    ): ?array {
        return $this->query
            ->table('employee_family')
            ->find($id);
    }

    public function create(
        array $data
    ): bool {
        return $this->query
            ->table('employee_family')
            ->insert($data);
    }

    public function update(
        int $id,
        array $data
    ): bool {
        return $this->query
            ->table('employee_family')
            ->where('id', $id)
            ->update($data);
    }

public function deactivate(
    int $id
): bool {
    return $this->query
        ->table('employee_family')
        ->where('id', $id)
        ->update([
            'status' => 0,
            'updated_at' =>
                date('Y-m-d H:i:s')
        ]);
}
}