<?php

namespace App\Models\Loaders;

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

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

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