<?php

namespace Modules\HR\Services;

use Illuminate\Support\Facades\DB;
use Modules\HR\DTO\HrSettingFilter;
use Modules\HR\Models\TaxConfiguration;
use Modules\HR\Repositories\TaxConfigurationRepository;

class TaxConfigurationService
{
    public function __construct(
        protected TaxConfigurationRepository $taxConfigurationRepo
    ) {}

    public function list(HrSettingFilter $filter)
    {
        $columns = ['id','minimum_tax','fiscal_year_id','status'];
        $with = ['fiscalYear:id,name'];
        return $this->taxConfigurationRepo->all($filter, $columns, $with);
    }

    public function show($id)
    {
        return $this->taxConfigurationRepo->find($id);
    }

    public function store(array $data)
    {
        return DB::transaction(function () use ($data) {
            return $this->taxConfigurationRepo->create($data);
        });
    }

    public function update(TaxConfiguration $taxConfiguration, array $data)
    {
        return DB::transaction(function () use ($taxConfiguration, $data) {
            return $this->taxConfigurationRepo->update($taxConfiguration, $data);
        });
    }

    public function updateStatus(TaxConfiguration $taxConfiguration, array $status)
    {
        return DB::transaction(function () use ($taxConfiguration, $status) {
            return $this->taxConfigurationRepo->updateStatus($taxConfiguration, $status);
        });
    }
}
