<?php

declare(strict_types=1);

namespace prj\{{.Root}}\logic\{{.Subfolder}};

use \bs_tts\safer_io as SafeIO;

class {{.File}}_logic {
    
    public static function {{.Method}}(array & $input): void {
        $model = new \prj\{{.Root}}\models\{{.Subfolder}}\{{.File}}_model(\main_tts\registry::get('db')); 
        
        $submitted = true;
        foreach(SafeIO::logic_sanitize($input) as $data) {
            if (SafeIO::required_fields_were_NOT_all_submitted($data)) {
                $submitted = false;
                break;
            }
        }
        
        $input['submitted'] = $submitted;
        
        if ($submitted) {
            $model->init_demo_table(); // Create Table if NOT exists!
            $model->populate(10); // INSERT 10 random rows of data

            $success = $model->save_index($input); // Save data from Request Data
            $input['model'] = ($success===true) ? 
                $model->get_index(15) : 
                $model->get_index(0);
        } else {
            $input['model'] = $model->get_index(0);
        }        
    }
    
}
