<?php

namespace App\Models;

use App\Models\Backoffice\Support\ContentTypeModel;
use App\Models\Backoffice\Traits\LanguageSupportTrait;

class ProcedureType extends ContentTypeModel
{
    use LanguageSupportTrait;

    protected $hidden = ['languages', "websites"];
    protected $with = ['languages', "websites"];

    protected $casts = [
        'is_active' => 'boolean',
        'in_competitions_filter' => 'boolean',
        'in_results_filter' => 'boolean',
        'is_announcement' => 'boolean',
        'is_open_to_students' => 'boolean'
    ];

    public function scopeIsActive($query)
    {
        $query->where('is_active', 1);
    }

    public function competitions()
    {
        return $this->belongsToMany(Competition::class, 'competition_procedure_types')
            ->withPivot('position')
            ->orderBy('competition_procedure_types.position');
    }
}
