<?php

namespace App\Http\Controllers\Admin;

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

class CompanyController extends BaseResourceController
{
  protected $model = Company::class;

  protected function indexQuery($query, Request $request)
  {
    $query->when($request->filled("status"), fn($q) => $q->where("status", $request->status));

    return $query;
  }

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

    return $page;
  }

  protected function validation(Request $request, $id = null): array
  {
    return [
      "validation" => [
        "code" => "required|string",
        "name" => "required|string",
        "status" => "required|string",
        "address" => "nullable|string",
      ],
      "default" => [
        "status" => \App\Enums\OriginStatusType::Active,
      ],
    ];
  }

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

    return [
      "status" => $status,

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