-- Interface Module: DlyDmdFst_Tx
-- Interface: Dly_Dmnd_Frcst_Out

-- Create sequence for bdi_seq_id column

CREATE SEQUENCE dly_dmnd_frcst_out_seq ORDER CACHE 20 MAXVALUE 9999999999999999999;


-- Create BDI Outbound Table: DLY_DMND_FRCST_OUT
-- This table is used to integrate daily demand forecast RDF-RMS.

CREATE TABLE DLY_DMND_FRCST_OUT (
  -- bdi internal column
  bdi_seq_id NUMBER DEFAULT dly_dmnd_frcst_out_seq.nextval NOT NULL,
  -- bdi internal column
  bdi_app_name VARCHAR2(50) DEFAULT sys_context('userenv', 'current_schema') NOT NULL,
  -- bdi internal column
  bdi_dataset_type VARCHAR2(20) DEFAULT 'FULL',
  -- bdi internal column
  bdi_dataset_action VARCHAR2(20) DEFAULT 'REPLACE',
  -- Holds date for the day, in YYYYMMDD format.
  day TIMESTAMP NOT NULL,
  -- Holds position name for sku.
  sku VARCHAR2(25) NOT NULL,
  -- Holds position name for stor.
  store VARCHAR2(10) NOT NULL,
  -- Approved Forecast - Day Level.
  appdayfrcst NUMBER(12,4),
  -- Approved Baseline Forecast - Day Level.
  appdaybaseline NUMBER(12,4),
  -- Approved Forecast Error - Day Level.
  appdaycumint NUMBER(12,4)
);

COMMENT ON TABLE DLY_DMND_FRCST_OUT IS 'This table is used to integrate daily demand forecast RDF-RMS.';
COMMENT ON COLUMN DLY_DMND_FRCST_OUT.bdi_seq_id IS 'bdi internal column';
COMMENT ON COLUMN DLY_DMND_FRCST_OUT.bdi_app_name IS 'bdi internal column';
COMMENT ON COLUMN DLY_DMND_FRCST_OUT.bdi_dataset_type IS 'bdi internal column';
COMMENT ON COLUMN DLY_DMND_FRCST_OUT.bdi_dataset_action IS 'bdi internal column';
COMMENT ON COLUMN DLY_DMND_FRCST_OUT.day IS 'Holds date for the day, in YYYYMMDD format.';
COMMENT ON COLUMN DLY_DMND_FRCST_OUT.sku IS 'Holds position name for sku.';
COMMENT ON COLUMN DLY_DMND_FRCST_OUT.store IS 'Holds position name for stor.';
COMMENT ON COLUMN DLY_DMND_FRCST_OUT.appdayfrcst IS 'Approved Forecast - Day Level.';
COMMENT ON COLUMN DLY_DMND_FRCST_OUT.appdaybaseline IS 'Approved Baseline Forecast - Day Level.';
COMMENT ON COLUMN DLY_DMND_FRCST_OUT.appdaycumint IS 'Approved Forecast Error - Day Level.';


-- Add BDI primary key constraint

ALTER TABLE DLY_DMND_FRCST_OUT ADD CONSTRAINT pk_dly_dmnd_frcst_out PRIMARY KEY (bdi_app_name, bdi_seq_id);


-- Add check constraint for bdi_dataset_type column

ALTER TABLE DLY_DMND_FRCST_OUT ADD CONSTRAINT chk_type_dly_dmnd_frcst_out CHECK (bdi_dataset_type IN ('FULL', 'PARTIAL'));


-- Add check constraint for bdi_dataset_action column

ALTER TABLE DLY_DMND_FRCST_OUT ADD CONSTRAINT chk_actn_dly_dmnd_frcst_out CHECK (bdi_dataset_action IN ('REPLACE', 'CREATE', 'UPDATE', 'DELETE'));
