<?php

namespace App\Http\Controllers\Admin;

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

class BalanceController extends BaseResourceController
{
  protected $model = Balance::class;

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

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

    return $page;
  }

  protected function validation(Request $request, $id = null): array
  {
    return [
      "validation" => [
        "company_id" => "required|integer|exists:companies,id",
        "code" => "required|string",
        "user_id" => "required|integer|exists:users,id",
        "department_id" => "required|integer|exists:departments,id",
        "debit_amount" => "required|integer",
        "credit_amount" => "required|integer",
        "year" => "required|string",
        "month" => "required|integer",
      ],
      "default" => [],
    ];
  }

  protected function getFormData(Request $request, $model = null): array
  {
    $formData = [];
    $companies = \App\Models\Company::selectOptions()->get();
    $users = \App\Models\User::selectOptions()->get();
    $departments = \App\Models\Department::selectOptions()->get();

    return [
      "companies" => $companies,
      "users" => $users,
      "departments" => $departments,

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