<?php

namespace Modules\Customer\Services;

use Modules\Customer\Entities\NewCustomer;

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


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

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

    public function add($request)
    {
        $customer=new NewCustomer();
        $customer->name=$request->name;
        $customer->mobile=$request->mobile;
        $customer->save();

        return successResponse([]);
    }

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