<?php

namespace Modules\CRMCore\App\Models;

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

class DealStage extends Model
{
    use HasFactory;

    protected $table = 'deal_stages';

    protected $fillable = [
        'pipeline_id',
        'name',
        'color',
        'position',
        'is_default_for_pipeline',
        'is_won_stage',
        'is_lost_stage',
    ];

    protected $casts = [
        'pipeline_id' => 'integer',
        'position' => 'integer',
        'is_default_for_pipeline' => 'boolean',
        'is_won_stage' => 'boolean',
        'is_lost_stage' => 'boolean',
        'created_at' => 'datetime',
        'updated_at' => 'datetime',
    ];

    /**
     * Get the pipeline this stage belongs to.
     */
    public function pipeline(): BelongsTo
    {
        return $this->belongsTo(DealPipeline::class, 'pipeline_id');
    }

    /**
     * Get all deals currently in this stage.
     */
    public function deals(): HasMany
    {
        return $this->hasMany(Deal::class);
    }
}
