<?php

namespace App\Models\Equipment;

use App\Traits\BelongsToTenant;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class EquipmentInspectionTemplate extends Model
{
    use BelongsToTenant;

    protected $fillable = [
        'tenant_id',
        'equipment_id',
        'item_no',
        'check_point',
        'check_item',
        'check_timing',
        'check_frequency',
        'check_method',
        'sort_order',
        'is_active',
    ];

    protected $casts = [
        'is_active' => 'boolean',
    ];

    public function equipment(): BelongsTo
    {
        return $this->belongsTo(Equipment::class, 'equipment_id');
    }

    public function scopeActive($query)
    {
        return $query->where('is_active', true);
    }

    public function getTimingLabelAttribute(): string
    {
        return match ($this->check_timing) {
            'operating' => '가동 중',
            'stopped' => '정지 시',
            default => $this->check_timing ?? '-',
        };
    }
}
