<?php

namespace Modules\Customer\Services;

use Modules\Customer\Entities\Customer;

class CustomerService
{
    public function list()
    {
        $customers=Customer::query()->orderByDesc('created_at')->paginate(30);
        return successResponse($customers);
    }

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

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

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

    public function add($request)
    {
        $customer=new Customer();
        $customer->first_name=$request->first_name;
        $customer->last_name=$request->last_name;
        $customer->mobile=$request->mobile;
        $customer->bank_number=$request->bank_number;
        $customer->address=$request->address;
        $customer->save();

        return successResponse([]);
    }

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