<?php

declare(strict_types=1);

namespace App\Controllers;

use App\Core\Controller;
use App\Models\DemoData;
use App\Services\DocumentGenerator;

final class ZdoiController extends Controller
{
    public function create(): string
    {
        return $this->view('zdoi/create', [
            'title' => 'ЗДОИ заявление',
            'institutions' => DemoData::institutions(),
        ]);
    }

    public function store(): string
    {
        if ($response = $this->ensureCsrf()) {
            return $response;
        }

        $document = (new DocumentGenerator())->generate('zdoi', $this->input());

        return $this->json(['ok' => true, 'document' => $document]);
    }
}
