<?php

namespace WPD\Domain;

final class CheckResult
{
    private $complete;
    private $cursor;
    private $findings;
    private $status;
    private $note;

    public function __construct($complete, array $cursor, array $findings, $status = 'correcta', $note = '')
    {
        $this->complete = (bool) $complete;
        $this->cursor = $cursor;
        $this->findings = array_map(function ($finding) {
            return $finding instanceof Finding ? $finding->toArray() : $finding;
        }, $findings);
        $this->status = (string) $status;
        $this->note = (string) $note;
    }

    public static function complete(array $findings = array(), $status = null, $note = '')
    {
        if ($status === null) {
            $status = count($findings) > 0 ? 'hallazgo' : 'correcta';
        }
        return new self(true, array(), $findings, $status, $note);
    }

    public function isComplete()
    {
        return $this->complete;
    }

    public function cursor()
    {
        return $this->cursor;
    }

    public function findings()
    {
        return $this->findings;
    }

    public function status()
    {
        return $this->status;
    }

    public function note()
    {
        return $this->note;
    }
}

