<?php

namespace Modules\HR\Services;

use Illuminate\Support\Facades\DB;
use Modules\HR\DTO\HrSettingFilter;
use Modules\HR\Models\BiometricDevice;
use Modules\HR\Repositories\BiometricDeviceRepository;

class BiometricDeviceService
{
    protected $biometricDeviceRepo;

    public function __construct(BiometricDeviceRepository $biometricDeviceRepo)
    {
        $this->biometricDeviceRepo = $biometricDeviceRepo;
    }

    public function list(HrSettingFilter $filter)
    {
        $columns = ['id',
        'branch_id',
        'name',
        'device_uid',
        'ip_address',
        'port',
        'location',
        'status'];
        return $this->biometricDeviceRepo->all($filter, $columns);
    }

    public function lookup(HrSettingFilter $filter)
    {
        $columns = ['id',
        'name',
        'device_uid',
        'status'];
        return $this->biometricDeviceRepo->all($filter, $columns);
    }

    public function show($id): ?BiometricDevice
    {
        return $this->biometricDeviceRepo->find($id);
    }

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

    public function update(BiometricDevice $biometricDevice, array $data)
    {
        return DB::transaction(function () use ($biometricDevice, $data) {
            return $this->biometricDeviceRepo->update($biometricDevice, $data);
        });
    }

    public function updateStatus(BiometricDevice $biometricDevice, array $status)
    {
        return DB::transaction(function () use ($biometricDevice, $status) {
            return $this->biometricDeviceRepo->updateStatus($biometricDevice, $status);
        });
    }
}
