<?php

namespace App\DBRealTestSupport;

use App\Modules\Shared\Application\Util;
use Illuminate\Support\Facades\DB;
use App\DBRealTestSupport\TableCreation as TC;

class TypeRoomMother
{
    public static function build1($id = 1)
    {
        $faker = \Faker\Factory::create();

        return [
            'Id_TypeRoom' => $id,
            'TypeRoom_Name' => $faker->text(rand(5, 250)),
            'TypeRoom_Abrv' => Util::generateString(4),
            'TypeRoom_Capacity' => rand(1, 3),
            'TypeRoom_Status' => $faker->randomElement([1, 2])
        ];
    }

    public static function push1($id = 1)
    {
        return self::push(self::build1($id));
    }

    private static function push($object)
    {
        $response = DB::select("CALL `sp_type_room_insert`(?,?,?,?)", [
            $object['TypeRoom_Name'],
            $object['TypeRoom_Abrv'],
            $object['TypeRoom_Capacity'],
            $object['TypeRoom_Status'],
        ]);
        if ($response[0]->Response_Success !== 1) {
            var_dump($object, $response);
        }
        $object['Id_TypeRoom'] = $response[0]->Response_Id;
        return $object;
    }

    public static function clear()
    {
        return array_merge(
            [
                TC::TYPE_ROOM,
                TC::TYPE_ROOM_TRANSL
            ]
        );
    }
}
