<?php

namespace App\Models;

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

class LeadSale extends Model
{
    protected $fillable = [
        'lead_id',
        'product_id',
        'created_by',
        'assigned_to',
        'sale_by',
        'sale_date',
        'price',
        'quantity',
        'total',
        'payment_type_id',
        'remarks',
        'incentive',
        'is_deleted',
        'created_at',
        'updated_at',
        'deleted_at',
    ];

    protected $casts = [
        'price' => 'decimal:4',
        'quantity' => 'decimal:4',
        'total' => 'decimal:4',
        'incentive' => 'decimal:4',
        'is_deleted' => 'boolean',
        'created_at' => 'datetime',
        'updated_at' => 'datetime',
        'deleted_at' => 'datetime',
    ];

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

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

    public function creator(): BelongsTo
    {
        return $this->belongsTo(User::class, 'created_by');
    }

    public function assignee(): BelongsTo
    {
        return $this->belongsTo(User::class, 'assigned_to');
    }

    public function sales_person(): BelongsTo
    {
        return $this->belongsTo(User::class, 'sale_by');
    }

    public function payment_type(): BelongsTo
    {
        return $this->belongsTo(PaymentType::class, 'payment_type_id');
    }
}
