<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Attributes\Fillable;
use Illuminate\Database\Eloquent\Model;

#[Fillable(['order_id', 'product_id', 'staff_id', 'product_name', 'product_type', 'progress_status', 'progress_note', 'progress_updated_at', 'quantity', 'unit_price', 'discount', 'line_total', 'is_reward_free_item', 'bonus_amount', 'bonus_paid_at'])]
class OrderDetail extends Model
{
    protected function casts(): array
    {
        return [
            'quantity' => 'decimal:3',
            'unit_price' => 'decimal:2',
            'discount' => 'decimal:2',
            'line_total' => 'decimal:2',
            'is_reward_free_item' => 'boolean',
            'bonus_amount' => 'decimal:2',
            'bonus_paid_at' => 'datetime',
            'progress_updated_at' => 'datetime',
        ];
    }

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

    public function product()
    {
        return $this->belongsTo(Product::class);
    }

    public function staff()
    {
        return $this->belongsTo(User::class, 'staff_id');
    }
}
