<?php

namespace App\Models;

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

/**
 * App\Models\UserEpisodesRecord.
 *
 * @property int                        $id          id
 * @property int                        $user_id     user_id
 * @property int                        $episodes_id 短剧ID
 * @property int                        $list_id     具体多少集集ID
 * @property string                     $price       支付金额 1:1 金币
 * @property string                     $discount    折扣金币
 * @property \Illuminate\Support\Carbon $updated_at  删除时间
 * @property string                     $deleted_at  删除时间
 * @property \Illuminate\Support\Carbon $created_at  创建时间
 *
 * @method static \Illuminate\Database\Eloquent\Builder|UserEpisodesRecord newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|UserEpisodesRecord newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|UserEpisodesRecord query()
 * @method static \Illuminate\Database\Eloquent\Builder|UserEpisodesRecord whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|UserEpisodesRecord whereDeletedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|UserEpisodesRecord whereDiscount($value)
 * @method static \Illuminate\Database\Eloquent\Builder|UserEpisodesRecord whereEpisodesId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|UserEpisodesRecord whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|UserEpisodesRecord whereListId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|UserEpisodesRecord wherePrice($value)
 * @method static \Illuminate\Database\Eloquent\Builder|UserEpisodesRecord whereUpdatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|UserEpisodesRecord whereUserId($value)
 *
 * @mixin \Eloquent
 *
 * @property int                   $status 状态
 * @property \App\Models\User|null $user
 *
 * @method static \Illuminate\Database\Eloquent\Builder|UserEpisodesRecord whereStatust($value)
 *
 * @property \App\Models\Episode|null      $episodes
 * @property \App\Models\EpisodesList|null $detail
 *
 * @method static \Illuminate\Database\Eloquent\Builder|UserEpisodesRecord filterUser()
 */
class UserEpisodesRecord extends Model
{
    use HasFactory;
    use UserScope;

    protected $casts = [
        'price' => 'integer',
    ];

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

    public function user()
    {
        return $this->belongsTo(User::class, 'user_id', 'id');
    }

    public function episodes()
    {
        return $this->belongsTo(Episode::class, 'episodes_id', 'id')->withTrashed();
    }

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