<?php

namespace App\DBRealTestSupport;

use Illuminate\Support\Facades\DB;

class ExtraTranslMother
{

    public static function build1($idExtra = null, $idLanguage = null, $id = 0)
    {
        $faker = \Faker\Factory::create();
        $idExtra = $idExtra ?? ExtraMother::push1()['Id_Extra'];
        $idLanguage = $idLanguage ?? LanguageMother::push1()['Id_Language'];
        return [
            'Id_Extra'              => $id,
            'ExtraTransl_Title'     => $faker->text(rand(5, 250)),
            'Id_Extra'              => $idExtra,
            'Id_Language'           => $idLanguage,
        ];
    }

    public static function push1($idExtra = null, $idLanguage = null, $id = 0)
    {
        return self::push(self::build1($idExtra, $idLanguage, $id));
    }

    private static function push($object)
    {
        $response = DB::select("CALL `sp_extra_transl_insert` (?,?,?,?)", [
            $object['ExtraTransl_Title'],
            $object['Id_Extra'],
            $object['Id_Language'],
            1
        ]);
        $object['Id_ExtraTransl'] = $response[0]->Response_Id;
        return $object;
    }
}
