<?php
namespace Misuzu\Profile;

use Index\Data\IDbResult;

class ProfileFieldInfo {
    private string $id;
    private int $order;
    private string $name;
    private string $title;
    private string $regex;

    public function __construct(IDbResult $result) {
        $this->id = (string)$result->getInteger(0);
        $this->order = $result->getInteger(1);
        $this->name = $result->getString(2);
        $this->title = $result->getString(3);
        $this->regex = $result->getString(4);
    }

    public function getId(): string {
        return $this->id;
    }

    public function getOrder(): int {
        return $this->order;
    }

    public function getName(): string {
        return $this->name;
    }

    public function getTitle(): string {
        return $this->title;
    }

    public function getRegEx(): string {
        return $this->regex;
    }

    public function checkValue(string $value): bool {
        return preg_match($this->regex, $value) === 1;
    }

    public function matchValue(string $value): string|false {
        return preg_match($this->regex, $value, $matches) === 1 ? $matches[1] : false;
    }
}
