<?php

namespace Modules\Inventory\Services;

use Modules\Inventory\Repositories\InventoryDepartmentRepository;
use Illuminate\Support\Facades\DB;
use Modules\Inventory\DTO\InventorySettingFilter;
use Modules\Inventory\Models\InventoryDepartment;
use Modules\Inventory\Models\Unit;

class InventoryDepartmentService
{
    protected $inventoryRepo;

    public function __construct(InventoryDepartmentRepository $inventoryRepo)
    {
        $this->inventoryRepo = $inventoryRepo;
    }

    public function list(InventorySettingFilter $filters)
    {
        $columns = ['id', 'name', 'code','status'];
        return $this->inventoryRepo->all($filters, $columns);
    }

    public function lookUpList(InventorySettingFilter $filters)
    {
        $columns = ['id', 'name', 'code'];

        return $this->inventoryRepo->all($filters, $columns);
    }

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

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

    public function update(InventoryDepartment $department, array $data)
    {
        return DB::transaction(function () use ($department, $data) {
            return $this->inventoryRepo->update($department, $data);
        });
    }

    public function updateStatus(InventoryDepartment $department, array $status)
    {
        return DB::transaction(function () use ($department, $status) {
            return $this->inventoryRepo->updateStatus($department, $status);
        });
    }
}
