USE [LegitimateKZN_QA_SO]
GO

/****** Object:  Table [App].[ApplicationRequestDetails]    Script Date: 2025/11/29 10:42:19 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [App].[ApplicationRequestDetails](
	[ApplicationRequestDetailID] [bigint] IDENTITY(1,1) NOT NULL,
	[WorkflowInstanceID] [bigint] NULL,
	[ApplicationRequestTypeID] [smallint] NOT NULL,
	[SourceApplicationID] [smallint] NOT NULL,
	[ProvinceID] [smallint] NOT NULL,
	[GazetteDetailID] [bigint] NULL,
	[AdjudicationDetailID] [bigint] NULL,
	[PrecheckDetailID] [bigint] NULL,
	[PaymentTypeID] [smallint] NULL,
	[IsRenewal] [bit] NOT NULL,
	[IsLateRenewal] [bit] NOT NULL,
	[IsNewAssociationRequired] [bit] NOT NULL,
	[IsNewMemberRequired] [bit] NOT NULL,
	[IsNewRouteRequired] [bit] NOT NULL,
	[IsExceptionRequired] [bit] NOT NULL,
	[IsUpliftmentRequired] [bit] NOT NULL,
	[IsAdjustmentRequired] [bit] NOT NULL,
	[Description] [varchar](500) NULL,
	[CreatedByID] [bigint] NOT NULL,
	[CreatedDate] [datetime] NOT NULL,
	[UpdatedByID] [bigint] NOT NULL,
	[UpdatedDate] [datetime] NOT NULL,
	[IsCancelled] [bit] NOT NULL,
	[IsCancellationRequired] [bit] NOT NULL,
	[RegionID] [bigint] NULL,
	[AdjudicationDecisionID] [smallint] NULL,
	[AdjudicationLicenceDurationMonths] [int] NULL,
	[AdjudicationDecisionDate] [datetime] NULL,
	[AdjudicationException] [bit] NULL,
	[AdjudicationLicenceExpiryDate] [date] NULL,
	[IsAdjudicationBypassed] [bit] NOT NULL,
	[AdjudicationRegionID] [smallint] NULL,
	[IsGazettingBypassed] [bit] NOT NULL,
	[IsAssessorApprovalRequired] [bit] NOT NULL,
	[IsSeniorManagerApprovalRequired] [bit] NOT NULL,
	[HasNewRoute] [bit] NOT NULL,
	[IsAutoVerificationRequired] [bit] NULL,
	[IsLtpsConversion] [bit] NULL,
	[IsBulkVehicleApplication] [bit] NOT NULL,
	[VehicleCount] [int] NOT NULL,
	[IsBulkVehicleVerificationRequired] [bit] NULL,
	[AdjudicationCount] [int] NULL,
	[IsReceiptRequired] [bit] NULL,
	[ForceGazetting] [bit] NULL,
	[AdjudicationTypeID] [smallint] NULL,
 CONSTRAINT [PK_ApplicationRequestDetails] PRIMARY KEY CLUSTERED 
(
	[ApplicationRequestDetailID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO

ALTER TABLE [App].[ApplicationRequestDetails] ADD  CONSTRAINT [DF_ApplicationRequestDetails_ApplicationRequestTypeID]  DEFAULT ((1)) FOR [ApplicationRequestTypeID]
GO

ALTER TABLE [App].[ApplicationRequestDetails] ADD  CONSTRAINT [DF_ApplicationRequestDetails_PaymentTypeID]  DEFAULT ((1)) FOR [PaymentTypeID]
GO

ALTER TABLE [App].[ApplicationRequestDetails] ADD  CONSTRAINT [DF_ApplicationRequestDetails_IsRenewal]  DEFAULT ((0)) FOR [IsRenewal]
GO

ALTER TABLE [App].[ApplicationRequestDetails] ADD  CONSTRAINT [DF_ApplicationRequestDetails_IsLateRenewal]  DEFAULT ((0)) FOR [IsLateRenewal]
GO

ALTER TABLE [App].[ApplicationRequestDetails] ADD  CONSTRAINT [DF_ApplicationRequestDetails_IsNewAssociationRequired]  DEFAULT ((0)) FOR [IsNewAssociationRequired]
GO

ALTER TABLE [App].[ApplicationRequestDetails] ADD  CONSTRAINT [DF_ApplicationRequestDetails_IsNewMemberRequired]  DEFAULT ((0)) FOR [IsNewMemberRequired]
GO

ALTER TABLE [App].[ApplicationRequestDetails] ADD  CONSTRAINT [DF_ApplicationRequestDetails_IsNewRouteRequired]  DEFAULT ((0)) FOR [IsNewRouteRequired]
GO

ALTER TABLE [App].[ApplicationRequestDetails] ADD  CONSTRAINT [DF_ApplicationRequestDetails_IsExceptionRequired]  DEFAULT ((0)) FOR [IsExceptionRequired]
GO

ALTER TABLE [App].[ApplicationRequestDetails] ADD  CONSTRAINT [DF_ApplicationRequestDetails_IsUpliftmentRequired]  DEFAULT ((1)) FOR [IsUpliftmentRequired]
GO

ALTER TABLE [App].[ApplicationRequestDetails] ADD  CONSTRAINT [DF_ApplicationRequestDetails_IsAdjustmentRequired]  DEFAULT ((0)) FOR [IsAdjustmentRequired]
GO

ALTER TABLE [App].[ApplicationRequestDetails] ADD  CONSTRAINT [DF_ApplicationRequestDetails_IsCancellationRequired]  DEFAULT ((0)) FOR [IsCancellationRequired]
GO

ALTER TABLE [App].[ApplicationRequestDetails] ADD  CONSTRAINT [DF__Applicati__Adjud__70BF5EF5]  DEFAULT ((0)) FOR [AdjudicationException]
GO

ALTER TABLE [App].[ApplicationRequestDetails] ADD  CONSTRAINT [DF__Applicati__IsAdj__131476F9]  DEFAULT ((0)) FOR [IsAdjudicationBypassed]
GO

ALTER TABLE [App].[ApplicationRequestDetails] ADD  CONSTRAINT [DF__Applicati__IsGaz__1AB598C1]  DEFAULT ((0)) FOR [IsGazettingBypassed]
GO

ALTER TABLE [App].[ApplicationRequestDetails] ADD  CONSTRAINT [DF__Applicati__IsAss__21629650]  DEFAULT ((0)) FOR [IsAssessorApprovalRequired]
GO

ALTER TABLE [App].[ApplicationRequestDetails] ADD  CONSTRAINT [DF__Applicati__IsSen__2256BA89]  DEFAULT ((0)) FOR [IsSeniorManagerApprovalRequired]
GO

ALTER TABLE [App].[ApplicationRequestDetails] ADD  CONSTRAINT [DF__Applicati__HasNe__234ADEC2]  DEFAULT ((0)) FOR [HasNewRoute]
GO

ALTER TABLE [App].[ApplicationRequestDetails] ADD  CONSTRAINT [DF__Applicati__IsAut__601EE2D8]  DEFAULT ((1)) FOR [IsAutoVerificationRequired]
GO

ALTER TABLE [App].[ApplicationRequestDetails] ADD  DEFAULT ((0)) FOR [IsLtpsConversion]
GO

ALTER TABLE [App].[ApplicationRequestDetails] ADD  DEFAULT ((0)) FOR [IsBulkVehicleApplication]
GO

ALTER TABLE [App].[ApplicationRequestDetails] ADD  DEFAULT ((1)) FOR [VehicleCount]
GO

ALTER TABLE [App].[ApplicationRequestDetails] ADD  DEFAULT ((0)) FOR [IsBulkVehicleVerificationRequired]
GO

ALTER TABLE [App].[ApplicationRequestDetails] ADD  DEFAULT ((0)) FOR [ForceGazetting]
GO

ALTER TABLE [App].[ApplicationRequestDetails]  WITH NOCHECK ADD  CONSTRAINT [FK_ApplicationRequestDetails_AdjudicationDetails] FOREIGN KEY([AdjudicationDetailID])
REFERENCES [App].[AdjudicationDetails] ([AdjudicationDetailID])
GO

ALTER TABLE [App].[ApplicationRequestDetails] CHECK CONSTRAINT [FK_ApplicationRequestDetails_AdjudicationDetails]
GO

ALTER TABLE [App].[ApplicationRequestDetails]  WITH NOCHECK ADD  CONSTRAINT [FK_ApplicationRequestDetails_ApplicationRequestTypes] FOREIGN KEY([ApplicationRequestTypeID])
REFERENCES [App].[ApplicationRequestTypes] ([ApplicationRequestTypeID])
GO

ALTER TABLE [App].[ApplicationRequestDetails] CHECK CONSTRAINT [FK_ApplicationRequestDetails_ApplicationRequestTypes]
GO

ALTER TABLE [App].[ApplicationRequestDetails]  WITH NOCHECK ADD  CONSTRAINT [FK_ApplicationRequestDetails_GazetteDetails] FOREIGN KEY([GazetteDetailID])
REFERENCES [App].[GazetteDetails] ([GazetteDetailID])
GO

ALTER TABLE [App].[ApplicationRequestDetails] CHECK CONSTRAINT [FK_ApplicationRequestDetails_GazetteDetails]
GO

ALTER TABLE [App].[ApplicationRequestDetails]  WITH NOCHECK ADD  CONSTRAINT [FK_ApplicationRequestDetails_PaymentTypes] FOREIGN KEY([PaymentTypeID])
REFERENCES [Md].[PaymentTypes] ([PaymentTypeID])
GO

ALTER TABLE [App].[ApplicationRequestDetails] CHECK CONSTRAINT [FK_ApplicationRequestDetails_PaymentTypes]
GO

ALTER TABLE [App].[ApplicationRequestDetails]  WITH NOCHECK ADD  CONSTRAINT [FK_ApplicationRequestDetails_PrecheckDetails] FOREIGN KEY([PrecheckDetailID])
REFERENCES [App].[PrecheckDetails] ([PrecheckDetailID])
GO

ALTER TABLE [App].[ApplicationRequestDetails] CHECK CONSTRAINT [FK_ApplicationRequestDetails_PrecheckDetails]
GO

ALTER TABLE [App].[ApplicationRequestDetails]  WITH NOCHECK ADD  CONSTRAINT [FK_ApplicationRequestDetails_Provinces] FOREIGN KEY([ProvinceID])
REFERENCES [Md].[Provinces] ([ProvinceID])
GO

ALTER TABLE [App].[ApplicationRequestDetails] CHECK CONSTRAINT [FK_ApplicationRequestDetails_Provinces]
GO

ALTER TABLE [App].[ApplicationRequestDetails]  WITH NOCHECK ADD  CONSTRAINT [FK_ApplicationRequestDetails_Regions] FOREIGN KEY([RegionID])
REFERENCES [Md].[Regions] ([RegionID])
GO

ALTER TABLE [App].[ApplicationRequestDetails] CHECK CONSTRAINT [FK_ApplicationRequestDetails_Regions]
GO

ALTER TABLE [App].[ApplicationRequestDetails]  WITH NOCHECK ADD  CONSTRAINT [FK_ApplicationRequestDetails_SourceApplications] FOREIGN KEY([SourceApplicationID])
REFERENCES [Md].[SourceApplications] ([SourceApplicationID])
GO

ALTER TABLE [App].[ApplicationRequestDetails] CHECK CONSTRAINT [FK_ApplicationRequestDetails_SourceApplications]
GO

ALTER TABLE [App].[ApplicationRequestDetails]  WITH NOCHECK ADD  CONSTRAINT [FK_ApplicationRequestDetails_WorkflowInstances] FOREIGN KEY([WorkflowInstanceID])
REFERENCES [Wf].[WorkflowInstances] ([WorkflowInstanceID])
GO

ALTER TABLE [App].[ApplicationRequestDetails] CHECK CONSTRAINT [FK_ApplicationRequestDetails_WorkflowInstances]
GO


