Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 20
0.00% covered (danger)
0.00%
0 / 12
CRAP
0.00% covered (danger)
0.00%
0 / 1
IntegrationResult
0.00% covered (danger)
0.00%
0 / 20
0.00% covered (danger)
0.00%
0 / 12
156
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
2
 getType
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getStatus
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getForeignId
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getError
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 isCreated
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 isFailed
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 isSkipped
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 toArray
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
2
 created
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 failed
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 skipped
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace BuyerKiosk\EventManagement\Models;
4
5/**
6 * IntegrationResult - Value object representing the result of an integration operation
7 *
8 * This immutable value object captures the outcome of attempting to create
9 * or process an integration during event creation. It tracks:
10 * - The integration type
11 * - The result status (created, failed, skipped)
12 * - The foreign ID if successfully created
13 * - Any error message if failed
14 *
15 * Used in API responses to provide detailed per-integration feedback.
16 *
17 * @package BuyerKiosk\EventManagement\Models
18 */
19class IntegrationResult
20{
21    // Result status constants
22    public const STATUS_CREATED = 'created';
23    public const STATUS_FAILED = 'failed';
24    public const STATUS_SKIPPED = 'skipped';
25
26    /**
27     * @var string The integration type (e.g., 'comeback_cash', 'sms_blast')
28     */
29    private string $type;
30
31    /**
32     * @var string Result status: 'created', 'failed', or 'skipped'
33     */
34    private string $status;
35
36    /**
37     * @var int|null Foreign ID of the created integration record (null if failed/skipped)
38     */
39    private ?int $foreignId;
40
41    /**
42     * @var string|null Error message if the integration failed (null if created/skipped)
43     */
44    private ?string $error;
45
46    /**
47     * Constructor
48     *
49     * @param string $type Integration type
50     * @param string $status Result status ('created', 'failed', 'skipped')
51     * @param int|null $foreignId Foreign ID if created successfully
52     * @param string|null $error Error message if failed
53     */
54    public function __construct(
55        string $type,
56        string $status,
57        ?int $foreignId = null,
58        ?string $error = null
59    ) {
60        $this->type = $type;
61        $this->status = $status;
62        $this->foreignId = $foreignId;
63        $this->error = $error;
64    }
65
66    /**
67     * Get the integration type
68     *
69     * @return string
70     */
71    public function getType(): string
72    {
73        return $this->type;
74    }
75
76    /**
77     * Get the result status
78     *
79     * @return string
80     */
81    public function getStatus(): string
82    {
83        return $this->status;
84    }
85
86    /**
87     * Get the foreign ID
88     *
89     * @return int|null
90     */
91    public function getForeignId(): ?int
92    {
93        return $this->foreignId;
94    }
95
96    /**
97     * Get the error message
98     *
99     * @return string|null
100     */
101    public function getError(): ?string
102    {
103        return $this->error;
104    }
105
106    /**
107     * Check if the integration was successfully created
108     *
109     * @return bool
110     */
111    public function isCreated(): bool
112    {
113        return $this->status === self::STATUS_CREATED;
114    }
115
116    /**
117     * Check if the integration failed
118     *
119     * @return bool
120     */
121    public function isFailed(): bool
122    {
123        return $this->status === self::STATUS_FAILED;
124    }
125
126    /**
127     * Check if the integration was skipped
128     *
129     * @return bool
130     */
131    public function isSkipped(): bool
132    {
133        return $this->status === self::STATUS_SKIPPED;
134    }
135
136    /**
137     * Convert to array for JSON serialization
138     *
139     * @return array
140     */
141    public function toArray(): array
142    {
143        return [
144            'type' => $this->type,
145            'status' => $this->status,
146            'foreignId' => $this->foreignId,
147            'error' => $this->error,
148        ];
149    }
150
151    /**
152     * Create a successful result
153     *
154     * @param string $type Integration type
155     * @param int $foreignId Foreign ID of created record
156     * @return self
157     */
158    public static function created(string $type, int $foreignId): self
159    {
160        return new self($type, self::STATUS_CREATED, $foreignId, null);
161    }
162
163    /**
164     * Create a failed result
165     *
166     * @param string $type Integration type
167     * @param string $error Error message
168     * @return self
169     */
170    public static function failed(string $type, string $error): self
171    {
172        return new self($type, self::STATUS_FAILED, null, $error);
173    }
174
175    /**
176     * Create a skipped result
177     *
178     * @param string $type Integration type
179     * @param string|null $reason Optional reason for skipping
180     * @return self
181     */
182    public static function skipped(string $type, ?string $reason = null): self
183    {
184        return new self($type, self::STATUS_SKIPPED, null, $reason);
185    }
186}