<?php

namespace Modules\Supplier\Services;

use Modules\Supplier\Entities\Supplier;

class SupplierService
{
    public function list()
    {
        $suppliers=Supplier::query()->orderByDesc('created_at')->paginate(30);
        return successResponse($suppliers);
    }

    public function chequeSuppliers()
    {
        $suppliers=Supplier::query()->orderByDesc('created_at')->select('id','first_name','last_name')->get();
        return successResponse($suppliers);
    }

    public function delete($id)
    {
        $supplier=Supplier::query()->where('id',$id)->first();
        if (!$supplier){
            return failedResponse('کاربر مورد نظر یافت نشد',404);
        }

        $supplier->delete();
        return   successResponse([]);
    }

    public function add($request)
    {
        $supplier=new Supplier();
        $supplier->first_name=$request->first_name;
        $supplier->last_name=$request->last_name;
        $supplier->mobile=$request->mobile;
        $supplier->bank_number=$request->bank_number;
        $supplier->iban=$request->iban;
        $supplier->address=$request->address;
        $supplier->save();

        return successResponse([]);
    }

    public function show($id)
    {
        $supplier=Supplier::query()->where('id',$id)->first();
        if (!$supplier){
            return failedResponse('کاربر مورد نظر یافت نشد',404);
        }
        return   successResponse(['supplier'=>$supplier]);
    }
}