<?php

namespace App\Http\Controllers\Admin;

use App\Models\CodeConfig;
use App\Utils\Helper;
use Illuminate\Http\Request;
use App\Enums\PublishStatusType;
use App\Http\Controllers\Core\BaseResourceController;

class CodeConfigController extends BaseResourceController
{
  protected $model = CodeConfig::class;

  protected function indexQuery($query, Request $request)
  {
    return $query;
  }

  protected function getPage(Request $request, $id = null): array
  {
    $page = [
      "name" => "code_configs",
      "inertia" => "Admin/CodeConfig",
      "label" => "Konfigurasi Kode",
      "url" => "/admin/code_configs",
      "fields" => Helper::getFormFields($this->validation($request)),
    ];

    return $page;
  }

  protected function validation(Request $request, $id = null): array
  {
    return [
      "validation" => [
        "module" => "required|string|unique:code_configs,module",
        "prefix" => "required|string",
        "separator" => "required|string",
        "digits" => "required|integer",
        "last_number" => "required|integer",
        "is_user_alias" => "required|boolean",
      ],
      "default" => [
        "module" => \App\Enums\ModuleType::Budget,
        "separator" => "/",
        "digits" => 4,
        "last_number" => 0,
        "is_user_alias" => false,
      ],
    ];
  }

  protected function getFormData(Request $request, $model = null): array
  {
    $formData = [];
    $modules = \App\Enums\ModuleType::getValues();

    return [
      "modules" => $modules,

      ...parent::getFormData($request, $model),
      ...$formData,
    ];
  }
}
