<?php

namespace App\Models;

use App\Libs\Database\Eloquent\ContentTypeModel;
use App\Models\GenericBackoffice\Traits\LanguageSupportTrait;

class Form extends ContentTypeModel
{
    use LanguageSupportTrait;

    protected $hidden = ['languages', "websites"];
    protected $with = ['languages', "websites"];

    public function formSections()
    {
        return $this->hasMany(FormSection::class, 'form_id', 'id');
    }

    public function responses()
    {
        return $this->hasMany(FormResponse::class);
    }

    public function block() {
        return $this->hasMany(Block::class);
    }

    /**
     * Contact address shown to participants (confirmation email + duplicate-submission notice).
     * Falls back to the site default when the form does not override it.
     */
    public function resolveContactEmail(): string
    {
        return $this->contact_email ?: config('mail.contact.block_form_address');
    }
}
