<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class OrderDetail extends Model
{
	protected $table = 'order_details';
	
	protected $fillable = [
		'id', 'order_id', 'product_id', 'product_detail_id', 'product_name',
		'product_image', 'product_type', 'order_method', 'discount', 'catalog_price', 'price',
		'tax', 'shipping_cost', 'shipping_date', 'wear_date', 'preferred_delivery_time', 'note',
		'height', 'hip', 'foot', 'sleeve', 'safe_pack', 'tabi', 'towel', 'free_options',
		'quantity', 'total_price', 'created_at', 'updated_at'];
	
	public function order()
	{
		return $this->belongsTo(Order::class, 'order_id', 'id');
	}

	public function product()
	{
		return $this->belongsTo(Product::class, 'product_id', 'id');
	}
	
	public function product_detail()
	{
		return $this->belongsTo(ProductDetail::class, 'product_detail_id', 'id')->with('product', 'option_detail');
	}
	
	public function product_owner()
	{
		return $this->belongsTo(Product::class, 'product_id', 'id')->select('id', 'owner_id', 'reward_amount')->with('owner');
	}
}
