<?php

namespace App\Repositories\Shop;

use App\Models\Shop\CustomerAddress;

class CustomerAddresses
{
    public static function getOptions()
    {
        return CustomerAddress::orderBy('name', 'asc')->get()->pluck('name', 'id')->toArray();
    }

    public static function getAll()
    {
        return CustomerAddress::orderBy('name', 'asc')->get();
    }

    public static function get($id)
    {
        return CustomerAddress::find($id);
    }

    public static function store($data)
    {
        $id = $data['id'] ?? false;
        $item = $id ? self::update($data, $id) : self::create($data);
        return $item->id;
    }

    public static function create($data)
    {
        return CustomerAddress::create($data);
    }

    public static function update($data, $id = false)
    {
        $id = $id ? $id : $data['id'];
        $delivery = self::get($id);
        $delivery->update($data);
        return $delivery;
    }

    public static function destroy($id)
    {
        return CustomerAddress::destroy($id);
    }

    public static function toggle_active($id, $active)
    {
        return self::update(['active' => $active], $id);
    }
}
