<?php

namespace App\Http\Controllers\v1\Tenancy\User;

use App\Http\Controllers\Controller;
use Illuminate\Http\Response;

class ToggleDefaultUserAddressController extends Controller
{
    public function __invoke(int $id): Response
    {
        $address = auth()->user()->addresses()->findOrFail($id);
        auth()->user()->addresses()->update(['default' => false]);
        $address->default = ! $address->default;
        $address->save();

        return $this->noContent();
    }
}
