*/ final class FormSubmissionFactory extends Factory { protected $model = FormSubmission::class; /** @return array */ public function definition(): array { return [ 'form_schema_id' => FormSchema::factory(), 'subject_type' => null, 'subject_id' => null, 'submitted_by_user_id' => null, 'status' => FormSubmissionStatus::DRAFT, 'is_test' => false, 'submitted_in_locale' => 'nl', ]; } public function submitted(): static { return $this->state(fn () => [ 'status' => FormSubmissionStatus::SUBMITTED, 'submitted_at' => now(), ]); } public function test(): static { return $this->state(fn () => ['is_test' => true]); } /** * Force a specific tenant. The observer would otherwise resolve it * from the schema parent; this state lets tests override for edge * cases (e.g. cross-org leakage scenarios in Commit 3). */ public function forOrganisation(Organisation $organisation): static { return $this->state(fn () => ['organisation_id' => $organisation->id]); } /** * Force a specific event + its organisation. Addendum Q2 contract: * any submission tied to an event also has that event's org. */ public function forEvent(Event $event): static { return $this->state(fn () => [ 'event_id' => $event->id, 'organisation_id' => $event->organisation_id, ]); } /** * Set failure_response_code. Typically used in tests asserting the * downstream rendering behaviour for failed submissions. * * Valid values per RFC-WS-6 §Q3 v1.3 addition 2: * - 'schema_config_error' * - 'temporary_error' * - 'data_integrity_error' * - 'unknown_error' * * Note: writing this value via factory does NOT itself set apply_status * to FAILED. Pair with an explicit apply_status attribute in tests * that need a coherent failed-submission fixture. */ public function withFailureResponseCode(string $code): static { return $this->state(fn () => ['failure_response_code' => $code]); } }