<?php

namespace Database\Seeders;

use App\Enums\DbStatusFieldEnum;
use App\Models\ProfitCenter;
use App\Models\Role;
use App\Models\User;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\Hash;

class ProfitCenterSeeder extends Seeder
{
    /**
     * Run the database seeds.
     */
    public function run(): void
    {
        $PC = ProfitCenter::create([
            'name' => 'ProfitCenter - Eurest Étterem',
            'hooreycaId' => 'HIDtest',
            'nameId' => 'NameID',
            'postCode' => 1212,
            'city' => 'Budapest',
            'street' => 'ProfitCenter tér 1.',
            'status' => DbStatusFieldEnum::active,
        ]);

        if (! $User = User::where('name', 'testProfitCenter')->first()) {
            $User = User::Create([
                'name' => 'testProfitCenter',
                'password' => Hash::make('123456'),
                'email' => 'test3@e98.hu',
            ]);
            $User->attachRole(Role::where('name', 'profit-center')->first());
        }
        $PC->users()->syncWithoutDetaching($User->id);

        $PC = ProfitCenter::create([
            'name' => 'Próba - Eurest Étterem',
            'hooreycaId' => 'proba',
            'nameId' => 'proba',
            'postCode' => 1221,
            'city' => 'Budapest',
            'street' => 'Próba 1.',
            'status' => DbStatusFieldEnum::active,
        ]);

        if (! $User = User::where('name', 'proba')->first()) {
            $User = User::Create([
                'name' => 'proba',
                'password' => Hash::make('proba123456'),
                'email' => 'beszerzes1@eurest.hu',
            ]);
            $User->attachRole(Role::where('name', 'profit-center')->first());
        }
        $PC->users()->syncWithoutDetaching($User->id);

        return;
        $o = new ProfitCenter;
        $data = [
            'name' => 'Hankook - Eurest Étterem',
            'hooreycaId' => 'HANKOK',
            'nameId' => 'HANKOK',
            'postCode' => 2459,
            'city' => 'Rácalmás',
            'street' => 'Hankook tér 1.',
            'status' => DbStatusFieldEnum::active,
        ];
        foreach ($data as $k => $v) {
            $o->{$k} = $v;
        }
        $o->save();

    }
}
