<?php

namespace Modules\Billing\Services;

use Illuminate\Support\Facades\DB;
use Modules\Billing\DTO\BillingSettingFilter;
use Modules\Billing\Models\ServiceDepartment;
use Modules\Billing\Repositories\ServiceDepartmentRepository;

class ServiceDepartmentService
{
    public function __construct(
        protected ServiceDepartmentRepository $serviceDepartmentRepo
    ) {}

    public function list(BillingSettingFilter $filter)
    {
        return $this->serviceDepartmentRepo->all($filter);
    }

    public function show(int $id): ServiceDepartment
    {
        return $this->serviceDepartmentRepo->find($id);
    }

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

    public function update(ServiceDepartment $serviceDepartment, array $data): ServiceDepartment
    {
        return DB::transaction(function () use ($serviceDepartment, $data) {
            return $this->serviceDepartmentRepo->update($serviceDepartment, $data);
        });
    }

    public function updateStatus(ServiceDepartment $serviceDepartment, array $status): ServiceDepartment
    {
        return DB::transaction(function () use ($serviceDepartment, $status) {
            return $this->serviceDepartmentRepo->updateStatus($serviceDepartment, $status);
        });
    }
}
