<?php

namespace 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 FieldJobSetting extends Model
{
    use HasFactory;

    protected $fillable = [
        'segment_id',
        'initial_decision_id',
        'assign_decision_id',
        'complete_decision_id',
        'cancel_decision_id',
        'return_segment_id',
        'queue_segment_id',
        'action_id',
    ];

    public function action(): BelongsTo
    {
        return $this->belongsTo(\App\Models\Action::class);
    }

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

    public function assignDecision(): BelongsTo
    {
        return $this->belongsTo(Decision::class, 'assign_decision_id')
            ->with(['actions' => function ($query) {
                $query->select('actions.id');
            }]);
    }

    public function initialDecision(): BelongsTo
    {
        return $this->belongsTo(Decision::class, 'initial_decision_id')
            ->with(['actions' => function ($query) {
                $query->select('actions.id');
            }]);
    }

    public function completeDecision(): BelongsTo
    {
        return $this->belongsTo(Decision::class, 'complete_decision_id')
            ->with(['actions' => function ($query) {
                $query->select('actions.id');
            }]);
    }

    public function cancelDecision(): BelongsTo
    {
        return $this->belongsTo(Decision::class, 'cancel_decision_id')
            ->with(['actions' => function ($query) {
                $query->select('actions.id');
            }]);
    }

    public function returnSegment(): BelongsTo
    {
        return $this->belongsTo(Segment::class, 'return_segment_id');
    }

    public function queueSegment(): BelongsTo
    {
        return $this->belongsTo(Segment::class, 'queue_segment_id');
    }

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