<?php

namespace Application\Controller\project\ae;


use Application\Common\StatusCode;
use Application\Form\project\AeForm;
use Application\Mvc\Controller\BasicController;
use Application\Service\DB\Dictionary\FormGroup;
use Application\Service\Extension\Formatter\Formatter;
use Application\Service\Extension\Formatter\FormFormatter;
use Application\Service\Extension\Helper\ArrayHelper;
use Laminas\View\Model\JsonModel;

class AeController extends BasicController
{
    /**
     * 渲染表格内容
     * @return JsonModel
     * @throws \Exception
     */
    public function indexAction(): JsonModel
    {
        $this->validator->attach(
            [['item_id', 'ae_type'], 'required']
        );

        if (!$this->validator->isValid()) {
            return $this->RenderApiJson()->Error(
                StatusCode::E_FIELD_VALIDATOR,
                $this->validator->getFirstErrorToString()
            );
        }

        $model = new AeForm($this->validator);
        $data = [];

        // 属于新增AE表单, 属于已有AE
        if (in_array($this->validator->attributes['ae_type'], [5, 6])) {
            $data = $model->renderNewAeTable();
        }

        return $this->RenderApiJson()->Success($data);
    }

}
