<?php

namespace App\Models\Loaders;

use Illuminate\Support\Facades\DB;
use App\Models\ORM\Event;

class GigsLoader
{
    public function getEvents(): array
    {
        $data = Event::select(
            "Event.Name as event",
            "Event.PlaceId as place_id",
            "places.name as place",
            "places.address as address",
            "places.phone as phone",
            "places.url as url",
            DB::Raw("DAY(Event.Date) as mday"),
            DB::Raw("MONTH(Event.Date) as month"),
            DB::Raw("DATE_FORMAT(Event.Time, '%H:%s') as time"),
            DB::Raw("CONCAT(DATE_FORMAT(Event.Date,'%Y-%m-%d'),
            'T',DATE_FORMAT(Event.Time, '%H:%i:%s')) as fulldate")
        )->join("places", function ($join){
            $join->on("places.id", "=", "Event.PlaceId")
                ->where("places.deleted_at", NULL);
        });
            $data = $data->get();

        return $data ? $data->toArray() : [];
    }
}
