<?php

namespace App\Models;

use App\Models\Admin\Estacion;
use App\Traits\HasSortsTrait;
use App\Traits\ImagenesGetterTrait;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Servicio extends Model
{
    use HasFactory, HasSortsTrait, ImagenesGetterTrait;

    protected $table = 'servicios';

    protected $fillable = [
        'titulo',
        'descripcion',
        'estado',
        'color'
    ];

    protected $dates = [
        'created_at',
        'updated_at'
    ];

    protected $casts = [
        'created_at' => 'datetime:d-m-Y H:i:s',
        'updated_at' => 'datetime:d-m-Y H:i:s',
    ];

    protected $appends = [
        'slug',
        'image'
    ];

    public function getImageAttribute()
    {
        return $this->imagen('medium');
    }

    public function getSlugAttribute()
    {
        if ($this->titulo) {
            return str_slug($this->titulo);
        }
    }

    public function estaciones()
    {
        return $this->belongsToMany(Estacion::class, 'estaciones_servicios');
    }

    public function activo($query)
    {
        return parent::activo();


        return $query->where('estado', true)
            ->where('fecha_desde', '>', Carbon::now())
            ->where('fecha_hasta', '<', Carbon::now());
    }
}
