<?php

namespace App\Models\Archives;

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

class ArchivedRecordRelation extends Model
{
    protected $table = 'archived_record_relations';

    protected $fillable = [
        'archived_record_id',
        'table_name',
        'data',
        'record_count',
    ];

    protected $casts = [
        'data' => 'array',
        'record_count' => 'integer',
        'archived_record_id' => 'integer',
    ];

    /**
     * 관계: 상위 아카이브 레코드
     */
    public function archivedRecord(): BelongsTo
    {
        return $this->belongsTo(ArchivedRecord::class, 'archived_record_id');
    }

    /**
     * 테이블명 레이블
     */
    public function getTableNameLabelAttribute(): string
    {
        return match ($this->table_name) {
            'users' => '사용자',
            'roles' => '역할',
            'permissions' => '권한',
            'departments' => '부서',
            'menus' => '메뉴',
            'products' => '제품',
            'materials' => '자재',
            'boms' => 'BOM',
            'categories' => '카테고리',
            'files' => '파일',
            'audit_logs' => '감사 로그',
            default => $this->table_name,
        };
    }
}
