<?php

namespace Formatrica\Submission\Validation;

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

/**
 * Value object representing validation results
 */
final class Validation_Result
{
    /** @var array<string, mixed> */
    private array $sanitised_data;

    /** @var array<string, string> */
    private array $errors;

    /** @var array<int, array<string, mixed>> */
    private array $field_meta;

    /**
     * @param array<string, mixed> $sanitised_data
     * @param array<string, string> $errors
     * @param array<int, array<string, mixed>> $field_meta
     */
    public function __construct(array $sanitised_data, array $errors, array $field_meta)
    {
        $this->sanitised_data = $sanitised_data;
        $this->errors = $errors;
        $this->field_meta = $field_meta;
    }

    /**
     * @return array<string, mixed>
     */
    public function get_sanitised_data(): array
    {
        return $this->sanitised_data;
    }

    /**
     * @return array<string, string>
     */
    public function get_errors(): array
    {
        return $this->errors;
    }

    /**
     * @return array<int, array<string, mixed>>
     */
    public function get_field_meta(): array
    {
        return $this->field_meta;
    }

    public function has_errors(): bool
    {
        return !empty($this->errors);
    }

    public function is_valid(): bool
    {
        return empty($this->errors);
    }

    /**
     * @return array{0: array<string, mixed>, 1: array<string, string>, 2: array<int, array<string, mixed>>}
     */
    public function to_tuple(): array
    {
        return [$this->sanitised_data, $this->errors, $this->field_meta];
    }
}
