<?php

namespace App\Http\Controllers\Dashboard\Company;

use App\Http\Controllers\Controller as ExController;
use Illuminate\Http\Request;
use App\Models\Company;

class CompanyController extends ExController
{
    public function index(Request $request)
    {
        $company = Company::first();
        return view('dashboard.company.index', compact('company'));
    }

    public function update(Request $request, $companyId)
    {
        $company = Company::findOrFail($companyId);

        $this->validate($request, [
            'company_name.uz' => 'required|string',
            'company_name.ru' => 'required|string',
            'inn' => 'required|string',
            'bank_name.uz' => 'required|string',
            'bank_name.ru' => 'required|string',
            'mfo' => 'required|string',
            'oked' => 'required|string',
            'address' => 'required|array',
            'address.uz' => 'required|string',
            'address.ru' => 'required|string',
            'director_full_name.uz' => 'required|string',
            'director_full_name.ru' => 'required|string',
            'payment_account' => 'required|string',
            'phone' => 'required|string',
        ]);

        $company->update([
            'company_name' => [
                "uz" => $request->company_name['uz'],
                "ru" => $request->company_name['ru'],
            ],
            'inn' => $request->inn,
            'bank_name' => [
                "uz" => $request->bank_name['uz'],
                "ru" => $request->bank_name['ru'],
            ],
            'mfo' => $request->mfo,
            'oked' => $request->oked,
            'address' => [
                'uz' => $request->address['uz'],
                'ru' => $request->address['ru']
            ],
            'director_full_name' => [
                "uz" => $request->director_full_name['uz'],
                "ru" => $request->director_full_name['ru'],
            ],
            'payment_account' => $request->payment_account,
            'phone' => $request->phone,
        ]);

        $this->info(trans('admin.messages.updated'));
        return redirect()->route('dashboard.companies.index');
    }
}
