<?php

declare(strict_types=1);

namespace App\Modules\Administration\Repositories;

use System\Database\QueryBuilder;

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

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

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

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

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

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

                'updated_at' =>
                    date('Y-m-d H:i:s')
            ]);
    }
}