<?php

namespace App\Models\ESign;

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

class EsignSignField extends Model
{
    use BelongsToTenant;

    protected $table = 'esign_sign_fields';

    // 필드 유형 상수
    public const TYPE_SIGNATURE = 'signature';
    public const TYPE_STAMP = 'stamp';
    public const TYPE_TEXT = 'text';
    public const TYPE_DATE = 'date';
    public const TYPE_CHECKBOX = 'checkbox';

    public const FIELD_TYPES = [
        self::TYPE_SIGNATURE,
        self::TYPE_STAMP,
        self::TYPE_TEXT,
        self::TYPE_DATE,
        self::TYPE_CHECKBOX,
    ];

    protected $fillable = [
        'tenant_id',
        'contract_id',
        'signer_id',
        'page_number',
        'position_x',
        'position_y',
        'width',
        'height',
        'field_type',
        'field_label',
        'field_variable',
        'font_size',
        'field_value',
        'is_required',
        'sort_order',
    ];

    protected $casts = [
        'page_number' => 'integer',
        'position_x' => 'decimal:2',
        'position_y' => 'decimal:2',
        'width' => 'decimal:2',
        'height' => 'decimal:2',
        'font_size' => 'integer',
        'is_required' => 'boolean',
        'sort_order' => 'integer',
    ];

    // === Relations ===

    public function contract(): BelongsTo
    {
        return $this->belongsTo(EsignContract::class, 'contract_id');
    }

    public function signer(): BelongsTo
    {
        return $this->belongsTo(EsignSigner::class, 'signer_id');
    }
}
