<?php

namespace App\Repositories\Customer;

use App\Models\Customer;
use App\Repositories\Customer\CustomerRepositoryInterface;


class CustomerRepository implements CustomerRepositoryInterface
{

    public function create(array $data)
    {
        return Customer::create($data);
    }
    public function find($id)
    {
        return Customer::find($id);
    }
    public function findByPhone($phone, $cod_phone)
    {
        return Customer::where('phone', $phone)
            ->where('cod_phone', $cod_phone)
            ->first();
    }
    public function update($id, $data)
    {
        $customer = Customer::find($id);
        $customer->update($data);
        return $customer;
    }

    public function updatecreate($data)
    {
        $customer = Customer::where('phone', $data['phone'])->first();
            $customer->update($data);

        // if ($customer) {
        //     $customer->update($data);
        // } else {
        //     $customer = Customer::create($data);
        // }
        return $customer;
    }
    public function delete($id)
    {
        return Customer::find($id)->delete();
    }
    public function getAll()
    {
        return Customer::all();
    }
    public function query()
    {
        return Customer::query();
    }
    public function restore($id)
    {
        return Customer::withTrashed()->find($id)->restore();
    }
}
