<?php

declare(strict_types=1);

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Plugins\Neatstudio\Payment\Models\Payment;

class MarketPackage extends Model
{
    protected $fillable = [
        'item_key', 'item_type', 'title', 'price', 'status', 'payment_id', 'user_id',
    ];

    public function payment(): BelongsTo
    {
        return $this->belongsTo(Payment::class);
    }

    public function isPaid(): bool
    {
        return $this->status === 'paid';
    }

    public function markPaid(Payment $payment): void
    {
        $this->update([
            'status' => 'paid',
            'payment_id' => $payment->id,
        ]);
    }

    /**
     * 作为可购买实体（市场商品）的展示约定。
     */
    public function payableLabel(): string
    {
        return '市场商品：'.$this->title;
    }

    public function payableUrl(): ?string
    {
        return null;
    }
}
