<?php

namespace App\Models;

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

class Emplette extends Model
{
    public const STATUS_DRAFT = 'draft';
    public const STATUS_SUBMITTED = 'submitted';
    public const STATUS_QUOTING = 'quoting';
    public const STATUS_QUOTED = 'quoted';
    public const STATUS_CLIENT_REVIEW = 'client_review';
    public const STATUS_ACCEPTED = 'accepted';
    public const STATUS_REJECTED = 'rejected';
    public const STATUS_CONVERTED = 'converted';

    protected $fillable = [
        'user_id',
        'status',
        'estimated_total',
        'final_total',
        'currency',
        // Compat: ancienne colonne unique (pouvait contenir note client ou note admin).
        'notes',
        'admin_notes',
        'client_notes',
        'order_id',
        'quote_sent_at',
    ];

    protected function casts(): array
    {
        return [
            'estimated_total' => 'decimal:2',
            'final_total' => 'decimal:2',
            'quote_sent_at' => 'datetime',
        ];
    }

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

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

    public function items(): HasMany
    {
        return $this->hasMany(EmpletteItem::class);
    }

    public function logs(): HasMany
    {
        return $this->hasMany(EmpletteLog::class);
    }
}

