<?php

namespace App\Models;

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

class EstimateLineItem extends Model
{
    use HasFactory;

    protected $fillable = [
        'estimate_id',
        'type', // 'labor', 'parts', 'miscellaneous'
        'part_id',
        'description',
        'quantity',
        'unit_price',
        'total_amount',
        'labor_hours',
        'labor_rate',
        'markup_percentage',
        'notes',
        'required',
        'category',
    ];

    protected $casts = [
        'quantity' => 'decimal:2',
        'unit_price' => 'decimal:2',
        'total_amount' => 'decimal:2',
        'labor_hours' => 'decimal:2',
        'labor_rate' => 'decimal:2',
        'markup_percentage' => 'decimal:2',
        'required' => 'boolean',
    ];

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

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