<?php

namespace App\Http\Controllers\CRM;

use App\Models\CRM\Individual;
use App\Http\Controllers\Controller;
use Illuminate\Http\RedirectResponse;
use App\Http\Requests\CRM\StorePassportRequest;
use App\Http\Requests\CRM\UpdatePassportRequest;

class PassportController extends Controller
{
    public function store(StorePassportRequest $request, Individual $individual): RedirectResponse
    {
        $data = $request->validated() + ['status' => 'active'];

        $individual->passports()->create($data['passport']);

        return redirect()->route('crm.individuals.edit', $individual)
            ->with('status', 'Passport added successfully!');
    }

    public function update(UpdatePassportRequest $request, Individual $individual): RedirectResponse
    {
        $data = $request->validated();

        $individual->passports()->update($data['passport']);

        return redirect()->route('crm.individuals.edit', $individual)
            ->with('status', 'Passport updated successfully!');
    }
}
