<?php

namespace App\Models;

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

class GeneratedDocument extends Model
{
    public const TYPE_ADMISSION_LETTER = 'admission_letter';
    public const TYPE_JOINING_INSTRUCTIONS = 'joining_instructions';
    public const TYPE_PAYMENT_RECEIPT = 'payment_receipt';

    protected $fillable = [
        'application_id', 'document_type', 'filename', 'storage_path',
        'disk', 'version', 'file_size', 'generated_by',
    ];

    public function application(): BelongsTo
    {
        return $this->belongsTo(Application::class);
    }

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

    public function label(): string
    {
        return match ($this->document_type) {
            self::TYPE_ADMISSION_LETTER => 'Admission Letter',
            self::TYPE_JOINING_INSTRUCTIONS => 'Joining Instructions',
            self::TYPE_PAYMENT_RECEIPT => 'Payment Receipt',
            default => ucwords(str_replace('_', ' ', $this->document_type)),
        };
    }
}
