<?php

namespace Modules\HR\Services;

use Illuminate\Support\Facades\DB;
use Modules\HR\DTO\HrSettingFilter;
use Modules\HR\Models\TaxSlab;
use Modules\HR\Repositories\TaxSlabRepository;

class TaxSlabService
{
    public function __construct(
        protected TaxSlabRepository $taxSlabRepo
    ) {}

    public function list(HrSettingFilter $filter)
    {
        $columns = ['id','name',
        'min_income','max_income','tax_type','tax_value','is_disabled','fiscal_year_id','status'];
        $with = ['fiscalYear:id,name'];
        return $this->taxSlabRepo->all($filter, $columns, $with);
    }

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

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

    public function update(TaxSlab $taxSlab, array $data)
    {
        return DB::transaction(function () use ($taxSlab, $data) {
            return $this->taxSlabRepo->update($taxSlab, $data);
        });
    }

    public function updateStatus(TaxSlab $taxSlab, array $status)
    {
        return DB::transaction(function () use ($taxSlab, $status) {
            return $this->taxSlabRepo->updateStatus($taxSlab, $status);
        });
    }
}
