<?php

namespace Kylin\Ecommerce\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\SoftDeletes;

/**
 * 退款/售后模型
 *
 * 依据《消费者权益保护法》第二十五条（7天无理由退货）
 * 和第二十四条（质量问题退货）及第五十五条（退一赔三）。
 */
class Refund extends Model
{
    use SoftDeletes;

    protected $table = 'ecommerce_refunds';

    protected $fillable = [
        'order_id', 'user_id', 'refund_no', 'type', 'status',
        'refund_amount', 'compensation_amount', 'reason',
        'evidence', 'reject_reason', 'refunded_at',
    ];

    protected $casts = [
        'refund_amount' => 'decimal:2',
        'compensation_amount' => 'decimal:2',
        'evidence' => 'array',
        'refunded_at' => 'datetime',
    ];

    public function order(): BelongsTo
    {
        return $this->belongsTo(Order::class, 'order_id');
    }

    public function user(): BelongsTo
    {
        return $this->belongsTo(\App\Models\User::class);
    }
}