<?php

namespace App\Models\BadDebts;

use App\Models\Commons\File;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class BadDebtDocument extends Model
{
    protected $fillable = [
        'bad_debt_id',
        'document_type',
        'file_id',
    ];

    /**
     * 서류 유형 상수
     */
    public const TYPE_BUSINESS_LICENSE = 'business_license';

    public const TYPE_TAX_INVOICE = 'tax_invoice';

    public const TYPE_ADDITIONAL = 'additional';

    /**
     * 서류 유형 목록
     */
    public const DOCUMENT_TYPES = [
        self::TYPE_BUSINESS_LICENSE => '사업자등록증',
        self::TYPE_TAX_INVOICE => '세금계산서',
        self::TYPE_ADDITIONAL => '추가서류',
    ];

    /**
     * 악성채권 관계
     */
    public function badDebt(): BelongsTo
    {
        return $this->belongsTo(BadDebt::class);
    }

    /**
     * 파일 관계
     */
    public function file(): BelongsTo
    {
        return $this->belongsTo(File::class);
    }

    /**
     * 서류 유형 라벨 속성
     */
    public function getDocumentTypeLabelAttribute(): string
    {
        return self::DOCUMENT_TYPES[$this->document_type] ?? $this->document_type;
    }
}
