<?php

namespace App\Services\Finance;

use App\Models\PrePayment;

class PrePaymentService
{
    public function markDeductedForPeriod(int $userId, int $companyId, int $year, int $month): int
    {
        return PrePayment::withoutGlobalScopes()
            ->where('company_id', $companyId)
            ->where('user_id', $userId)
            ->where('year', $year)
            ->where('month', $month)
            ->where('status', PrePayment::STATUS_PENDING)
            ->update(['status' => PrePayment::STATUS_DEDUCTED]);
    }

    public function revertDeductedForPeriod(int $companyId, int $year, int $month): int
    {
        return PrePayment::withoutGlobalScopes()
            ->where('company_id', $companyId)
            ->where('year', $year)
            ->where('month', $month)
            ->where('status', PrePayment::STATUS_DEDUCTED)
            ->update(['status' => PrePayment::STATUS_PENDING]);
    }
}
