<?php

namespace App\Models\Qualitys;

use App\Models\User;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;

class AuditChecklistItem extends Model
{
    protected $table = 'audit_checklist_items';

    protected $fillable = [
        'tenant_id',
        'category_id',
        'name',
        'description',
        'is_completed',
        'completed_at',
        'completed_by',
        'sort_order',
        'options',
    ];

    protected $casts = [
        'is_completed' => 'boolean',
        'completed_at' => 'datetime',
        'sort_order' => 'integer',
        'options' => 'array',
    ];

    public function category(): BelongsTo
    {
        return $this->belongsTo(AuditChecklistCategory::class, 'category_id');
    }

    public function completedByUser(): BelongsTo
    {
        return $this->belongsTo(User::class, 'completed_by');
    }

    public function standardDocuments(): HasMany
    {
        return $this->hasMany(AuditStandardDocument::class, 'checklist_item_id');
    }
}
