<?php

namespace App\Models\Qualitys;

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

class AuditChecklistCategory extends Model
{
    protected $table = 'audit_checklist_categories';

    protected $fillable = [
        'tenant_id',
        'checklist_id',
        'title',
        'sort_order',
        'options',
    ];

    protected $casts = [
        'sort_order' => 'integer',
        'options' => 'array',
    ];

    public function checklist(): BelongsTo
    {
        return $this->belongsTo(AuditChecklist::class, 'checklist_id');
    }

    public function items(): HasMany
    {
        return $this->hasMany(AuditChecklistItem::class, 'category_id')->orderBy('sort_order');
    }
}
