<?php

declare(strict_types=1);

namespace App\Modules\Administration\Repositories;

use System\Database\QueryBuilder;

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

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

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

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

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

    public function updateStatus(
        int $id,
        int $status
    ): bool {
        return $this->query
            ->table(
                'employee_rank_promotion_history'
            )
            ->where(
                'id',
                $id
            )
            ->update([
                'status' =>
                    $status,

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