<?php

namespace App;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Quote extends BaseModel
{
    use HasFactory;

    protected $table = 'quotes';
    
    protected $fillable = [
	    'id', 'type', 'code', 'customer_id', 'company', 'gender', 'estimated_date', 'estimated_amount', 'construction_name',
	    'construction_time', 'quote_expiration_date', 'labor_cost_ratio', 'employer_burden', 'legal_welfare_costs',
	    'removal_work_cost', 'removal_work_cost_unit', 'sheet_material_cost', 'sheet_material_cost_unit',
	    'transportation_fee', 'transportation_fee_unit', 'overhead_expenses', 'overhead_expenses_unit',
	    'content', 'total_amount', 'user_id', 'pdf_file', 'template', 'is_new', 'is_activated', 'is_deleted', 'created_at', 'updated_at'
    ];

    public function header() {
        return $this->hasMany(QuoteDetail::class, 'quote_id', 'id')->where('type', 0);
    }

    public function detail() {
        return $this->hasMany(QuoteDetail::class, 'quote_id', 'id')->where('type', 1);
    }
	
	public function customer()
	{
		return $this->belongsTo(Customer::class, 'customer_id', 'id')->with('project');
	}
}
