<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Episode extends Model
{
    use HasFactory;

    use SoftDeletes;

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

    protected $casts = [
        'episode_date' => 'date',
        'created_at' => 'datetime',
        'updated_at' => 'datetime',
        'deleted_at' => 'datetime',
    ];

    public function podcast()
    {
        return $this->belongsTo(Podcast::class);
    }

    public function artwork()
    {
        return $this->hasOne(Artwork::class, 'id', 'artwork_id');
    }

    public function approvedArtworks()
    {
        return $this->hasMany(Artwork::class)->whereNotNull('artworks.approved_by');
    }

    public function artworks()
    {
        return $this->hasMany(Artwork::class);
    }

    public function artist()
    {
        return $this->hasOneThrough(Artist::class, Artwork::class);
    }

}
