<?php

namespace App\Repositories\Shop;

use App\Models\Shop\CustomerAddress;
use App\Traits\Model\Basic;

class CustomerAddresses
{
    use Basic;

    public static function add($userId, $data)
    {
        $name = $data['company'] ? $data['company'] : $data['first_name'].' '.$data['last_name'];
        if ($data['use_for_delivery'] ?? false) {
            return self::store([
                'customer_id' => $userId,
                'name' => $name,
                'address' => $data['delivery_address'],
                'address2' => $data['delivery_address2'],
                'zipcode' => $data['delivery_zipcode'],
                'city' => $data['delivery_city'],
            ]);
        } else {
            return self::store([
                'customer_id' => $userId,
                'name' => $name,
                'address' => $data['address'],
                'address2' => $data['address2'],
                'zipcode' => $data['zipcode'],
                'city' => $data['city'],
            ]);
        }
    }

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

    public static function getModel()
    {
        return CustomerAddress::query();
    }
}
