<?php
namespace App\DTOs\Contracts;

use App\Contracts\ContractResult;

class ContractResponse
{
    public bool $success;
    public ?ContractResult $result;
    public ?string $error;
    public ?string $context;
    public int $status;

    public function __construct(
        bool $success,
        ?ContractResult $result = null,
        ?string $error = null,
        ?string $context = null,
        int $status = 200
    ) {
        $this->success = $success;
        $this->result = $result;
        $this->error = $error;
        $this->context = $context;
        $this->status = $status;
    }

    public static function success(ContractResult $result): self
    {
        return new self(true, $result, null, null, 200);
    }

    public static function failure(string $error, ?string $context = null, int $status = 422): self
    {
        return new self(false, null, $error, $context, $status);
    }
}