<?php

namespace App\DBRealTestSupport\TransactionSupported\Session;

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

class TSTypeDocumentMother
{

  public static function buildRandom($id = 1)
  {
    $faker = Factory::create();
    return [
      'Id_TypeDocument' => $id,
      'TypeDocument_Name' => $faker->text(rand(5, 250)),
      'TypeDocument_Abrv' => Util::generateString(4),
      'TypeDocument_ForPassenger' => $faker->randomElement([1, 2]),
      'TypeDocument_ConsetturId'  => $faker->randomNumber(3),
      'TypeDocument_Status' => 2
    ];
  }

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

  public static function push($object)
  {
    DB::insert(
      "INSERT INTO `t_type_document` 
        (
            `TypeDocument_Name`,
            `TypeDocument_Abrv`,
            `TypeDocument_ForPassenger`,
            `TypeDocument_ConsetturId`,
            `TypeDocument_Order`,
            `TypeDocument_Status`
        )
        VALUES (?, ?, ?, ?, ?, ?)",
      [
        $object['TypeDocument_Name'],
        $object['TypeDocument_Abrv'],
        $object['TypeDocument_ForPassenger'],
        $object['TypeDocument_ConsetturId'],
        1,
        $object['TypeDocument_Status']
      ]
    );
    $object['Id_TypeDocument'] = DB::select('SELECT LAST_INSERT_ID() as `Id`')[0]->Id;
    return $object;
  }

  public static function tablesToClear()
  {
    return [TC::TYPE_DOCUMENT, TC::TYPE_DOCUMENT_TRANSL];
  }
}
