<?php

declare(strict_types=1);

namespace common\forms;

use yii\base\Model;

/**
 * LeadForm — validation form for creating/editing a lead.
 */
class LeadForm extends Model
{
    public string $name    = '';
    public string $phone   = '';
    public ?string $email   = null;
    public ?string $source  = null;
    public ?string $interest = null;
    public ?string $message  = null;
    public string $status  = 'new';

    public function rules(): array
    {
        return [
            [['name', 'phone'], 'required'],
            [['name'], 'string', 'max' => 100],
            [['phone'], 'string', 'max' => 20],
            [['phone'], 'match', 'pattern' => '/^[+0-9\s\-()]{7,20}$/', 'message' => 'Enter a valid phone number.'],
            [['email'], 'email'],
            [['email'], 'string', 'max' => 150],
            [['source', 'interest'], 'string', 'max' => 100],
            [['message'], 'string'],
            [['status'], 'in', 'range' => ['new', 'contacted', 'converted', 'lost']],
            [['status'], 'default', 'value' => 'new'],
        ];
    }

    public function attributeLabels(): array
    {
        return [
            'name'     => 'Full Name',
            'phone'    => 'Phone Number',
            'email'    => 'Email Address',
            'source'   => 'Lead Source',
            'interest' => 'Interest / Goal',
            'message'  => 'Message',
            'status'   => 'Status',
        ];
    }
}
