<?php

namespace App\Models\Qualitys;

use App\Traits\Auditable;
use App\Traits\BelongsToTenant;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;

class AuditChecklist extends Model
{
    use Auditable, BelongsToTenant, SoftDeletes;

    protected $table = 'audit_checklists';

    const STATUS_DRAFT = 'draft';

    const STATUS_IN_PROGRESS = 'in_progress';

    const STATUS_COMPLETED = 'completed';

    const TYPE_STANDARD_MANUAL = 'standard_manual';

    protected $fillable = [
        'tenant_id',
        'year',
        'quarter',
        'type',
        'status',
        'options',
        'created_by',
        'updated_by',
        'deleted_by',
    ];

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

    public function categories(): HasMany
    {
        return $this->hasMany(AuditChecklistCategory::class, 'checklist_id')->orderBy('sort_order');
    }

    public function isDraft(): bool
    {
        return $this->status === self::STATUS_DRAFT;
    }

    public function isCompleted(): bool
    {
        return $this->status === self::STATUS_COMPLETED;
    }
}
