-- Interface Module: CompanyClosed_Fnd
-- Interface: Company_Closed_Out

-- Create sequence for bdi_seq_id column

CREATE SEQUENCE company_closed_out_seq ORDER CACHE 20 MAXVALUE 9999999999999999999;


-- Create BDI Outbound Table: COMPANY_CLOSED_OUT
-- This table is used to integrate company-wide closing information.

CREATE TABLE COMPANY_CLOSED_OUT (
  -- bdi internal column
  bdi_seq_id NUMBER DEFAULT company_closed_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',
  -- Contains the date that the company is closed.
  close_date TIMESTAMP NOT NULL,
  -- Contains a description of the close.
  close_desc VARCHAR2(120)
);

COMMENT ON TABLE COMPANY_CLOSED_OUT IS 'This table is used to integrate company-wide closing information.';
COMMENT ON COLUMN COMPANY_CLOSED_OUT.bdi_seq_id IS 'bdi internal column';
COMMENT ON COLUMN COMPANY_CLOSED_OUT.bdi_app_name IS 'bdi internal column';
COMMENT ON COLUMN COMPANY_CLOSED_OUT.bdi_dataset_type IS 'bdi internal column';
COMMENT ON COLUMN COMPANY_CLOSED_OUT.bdi_dataset_action IS 'bdi internal column';
COMMENT ON COLUMN COMPANY_CLOSED_OUT.close_date IS 'Contains the date that the company is closed.';
COMMENT ON COLUMN COMPANY_CLOSED_OUT.close_desc IS 'Contains a description of the close.';


-- Add BDI primary key constraint

ALTER TABLE COMPANY_CLOSED_OUT ADD CONSTRAINT pk_company_closed_out PRIMARY KEY (bdi_app_name, bdi_seq_id);


-- Add check constraint for bdi_dataset_type column

ALTER TABLE COMPANY_CLOSED_OUT ADD CONSTRAINT chk_type_company_closed_out CHECK (bdi_dataset_type IN ('FULL', 'PARTIAL'));


-- Add check constraint for bdi_dataset_action column

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