json($fn())->header('Cache-Control','no-store, private');}catch(\Illuminate\Database\QueryException $e){if(!in_array($e->errorInfo[0]??null,['55P03','57014'],true))throw $e;return response()->json(['message'=>'Orçamento ocupado. Recupere a mesma decisão.'],503)->header('Retry-After','5');}} public function index(Request $r,CommercialQuotes $s){return $this->response(fn()=>$s->listing($r->user()->id,$r->query()));} public function options(Request $r,CommercialQuotes $s){return $this->response(fn()=>$s->options($r->user()->id,$r->query()));} public function history(Request $r,CommercialQuotes $s,string $key){$d=$r->validate(['page'=>'sometimes|integer|min:1|max:100000']);abort_if(array_diff(array_keys($r->query()),['page']),422);return $this->response(fn()=>$s->history($r->user()->id,$key,(int)($d['page']??1)));} public function preview(Request $r,CommercialQuotes $s){return $this->response(fn()=>$s->preview($r->user()->id,$r->all(),strtolower((string)$r->header('Idempotency-Key'))));} public function confirm(Request $r,CommercialQuotes $s){$d=$r->validate(['preview'=>'required|string|max:131072']);abort_if(array_diff(array_keys($r->all()),['preview']),422);return $this->response(fn()=>$s->confirm($r->user()->id,$d['preview']));} public function print(Request $r,CommercialQuotes $s,string $key){$d=$r->validate(['version'=>'required|integer|min:1']);abort_if(array_diff(array_keys($r->query()),['version']),422);return response()->view('commercial.quote-print',['quote'=>$s->document($r->user()->id,$key,(int)$d['version'])])->header('Cache-Control','no-store, private');} }