<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class ShopShip extends Model
{
    protected $guarded = [];

    protected function shop()
    {
        return $this->belongsTo(Shop::class, 'shop_id', 'id');
    }

    public function getStatusAttribute($value)
    {
        $map = [
            0 => '未授权',
            1 => '已授权',
            3 => '停用',
        ];
        if (1 === (int)$value && ($this->attributes['expires_at'] - time()) / 3600 <= 72) {
            return '重新授权';
        }

        return $map[$value];
    }

    public function getExpiresAtAttribute($value)
    {
        return $value ? date('Y-m-d H:i:s', $value) : '';
    }

    public function senders()
    {
        return $this->hasMany(ShopSender::class, 'shop_ship_id');
    }
}
