<?php

namespace App\Models;

use App\Scopes\UserScope;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

/**
 * App\Models\UserWatchRecord.
 *
 * @property int                             $id
 * @property int                             $user_id    user_id
 * @property int                             $episode_id 短剧ID
 * @property int                             $list_id    具体集数ID
 * @property \Illuminate\Support\Carbon|null $updated_at
 * @property string|null                     $deleted_at
 * @property \Illuminate\Support\Carbon|null $created_at
 *
 * @method static \Illuminate\Database\Eloquent\Builder|UserWatchRecord newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|UserWatchRecord newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|UserWatchRecord query()
 * @method static \Illuminate\Database\Eloquent\Builder|UserWatchRecord whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|UserWatchRecord whereDeletedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|UserWatchRecord whereEpisodeId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|UserWatchRecord whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|UserWatchRecord whereListId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|UserWatchRecord whereUpdatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|UserWatchRecord whereUserId($value)
 *
 * @mixin \Eloquent
 *
 * @property \App\Models\Episode|null $episode
 *
 * @method static \Illuminate\Database\Query\Builder|UserWatchRecord onlyTrashed()
 * @method static \Illuminate\Database\Query\Builder|UserWatchRecord withTrashed()
 * @method static \Illuminate\Database\Query\Builder|UserWatchRecord withoutTrashed()
 *
 * @property \App\Models\EpisodesList|null $detail
 *
 * @method static \Illuminate\Database\Eloquent\Builder|UserWatchRecord user(\Illuminate\Database\Eloquent\Model $model)
 * @method static \Illuminate\Database\Eloquent\Builder|UserWatchRecord filterUser()
 */
class UserWatchRecord extends Model
{
    use HasFactory;
    use SoftDeletes;
    use UserScope;

    protected function serializeDate(\DateTimeInterface $date)
    {
        return $date->format($this->dateFormat ?: 'Y-m-d H:i:s');
    }

    public function episode()
    {
        return $this->belongsTo(Episode::class, 'episode_id', 'id');
    }

    public function detail()
    {
        return $this->belongsTo(EpisodesList::class, 'list_id', 'id');
    }
}
