<?php

namespace App\Http\Controllers\CRM;

use App\Http\Controllers\Controller;
use App\Http\Requests\CRM\StoreIdCardRequest;
use App\Http\Requests\CRM\UpdateIdCardRequest;
use App\Models\CRM\Individual;
use Illuminate\Http\RedirectResponse;

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

        $individual->idCards()->create($data);

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

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

        $individual->idCards()->update($data);

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