Maintain local ⭤ remote in sync with automatic AT Protocol parity for Laravel (alpha & unstable)
at dev 1.5 kB view raw
1<?php 2 3namespace SocialDept\AtpParity\Sync; 4 5use Illuminate\Database\Eloquent\Model; 6 7/** 8 * Value object representing the result of conflict resolution. 9 */ 10readonly class ConflictResolution 11{ 12 public function __construct( 13 public bool $resolved, 14 public string $winner, 15 public ?Model $model = null, 16 public ?PendingConflict $pending = null, 17 ) {} 18 19 /** 20 * Check if the conflict was resolved. 21 */ 22 public function isResolved(): bool 23 { 24 return $this->resolved; 25 } 26 27 /** 28 * Check if the conflict requires manual resolution. 29 */ 30 public function isPending(): bool 31 { 32 return ! $this->resolved && $this->pending !== null; 33 } 34 35 /** 36 * Create resolution where remote wins. 37 */ 38 public static function remoteWins(Model $model): self 39 { 40 return new self( 41 resolved: true, 42 winner: 'remote', 43 model: $model, 44 ); 45 } 46 47 /** 48 * Create resolution where local wins. 49 */ 50 public static function localWins(Model $model): self 51 { 52 return new self( 53 resolved: true, 54 winner: 'local', 55 model: $model, 56 ); 57 } 58 59 /** 60 * Create pending resolution for manual review. 61 */ 62 public static function pending(PendingConflict $conflict): self 63 { 64 return new self( 65 resolved: false, 66 winner: 'manual', 67 pending: $conflict, 68 ); 69 } 70}