<?php

namespace App\Models;

use App\Constants\Util;
use Illuminate\Database\Eloquent\Relations\HasMany;

/**
 * @property string $title
 * @property string sub_title
 * @property string detail_image
 * @property string start_time
 * @property string end_time
 * @property string status
 *
 */
class ActivityReward extends BaseModel
{
    const STATUS_UP = 1;
    const STATUS_DOWN = 0;

    protected $table = 'activity_rewards';
    protected $fillable = ['title', 'sub_title', 'detail_image', 'start_time', 'end_time', 'status','type','lang','content', 'params','pc_image','detail_banner', 'pc_banner'];

    public function activityUser(): HasMany
    {
        return $this->hasMany(ActivityUser::class, 'activity_id', 'id');
    }

    protected function getDetailImageAttribute($value)
    {
        return Util::ensureUrl($value);
    }

    protected function setDetailImageAttribute($value)
    {
        $this->attributes['detail_image'] = Util::replacePartInUrl($value);
    }

    protected function getPcImageAttribute($value)
    {
        return Util::ensureUrl($value);
    }

    protected function setPcImageAttribute($value)
    {
        $this->attributes['pc_image'] = Util::replacePartInUrl($value);
    }

    protected function getStartTimeAttribute($value): string
    {
        return date('Y-m-d', $value);
    }

    protected function getEndTimeAttribute($value): string
    {
        return date('Y-m-d', $value);
    }

}
