<?php

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

use App\Http\Controllers\Controller;
use App\Models\Tenancy\CanceledVisit;
use App\Models\Tenancy\Visit;

class CancelVisitController extends Controller
{
    public function __invoke(int $id)
    {
        $visit = Visit::findOrFail($id);
        CanceledVisit::create([
            'visit_id' => $visit->id,
            'client_id' => $visit->client_id,
            'date' => $visit->date,
            'visit_ends' => $visit->visit_ends,
            'specialist_id' => $visit->specialist_id,
            'specialist_name' => $visit->specialist_name,
            'type' => $visit->type,
            'online' => $visit->online,
        ]);
        $visit->delete();

        return $this->noContent();
    }
}
