CREATE TABLE `datawarehouse`.`us2_authnet_credentials` (
  `authnet_credentials_id` INT NOT NULL AUTO_INCREMENT,
  `type` ENUM('DEV','PROD') NOT NULL,
  `api_login_id` VARCHAR(25) NOT NULL,
  `transaction_key` VARCHAR(16) NOT NULL,
  PRIMARY KEY (`authnet_credentials_id`));

CREATE TABLE `datawarehouse`.`us2_authnet_customer_profile` (
  `authnet_customer_profile_id` INT NULL AUTO_INCREMENT,
  `client_id` INT NOT NULL DEFAULT 0,
  `customer_id` INT NOT NULL DEFAULT 0,
  `customer_profile_id` INT NOT NULL,
  `active_yn` CHAR(1) NOT NULL DEFAULT 'Y',
  PRIMARY KEY (`authnet_customer_profile_id`),
  INDEX `customer_id` (`customer_id` ASC),
  INDEX `customer_profile_id` (`customer_profile_id` ASC));

CREATE TABLE `datawarehouse`.`us2_authnet_payment_profile` (
  `authnet_payment_profile_id` INT NOT NULL AUTO_INCREMENT,
  `customer_profile_id` INT NOT NULL,
  `payment_profile_id` INT NOT NULL,
  `last_four` VARCHAR(4) NULL,
  `active_yn` CHAR(1) NOT NULL DEFAULT 'Y',
  PRIMARY KEY (`authnet_payment_profile_id`),
  INDEX `customer_profile_id` (`customer_profile_id` ASC),
  INDEX `payment_profile_id` (`payment_profile_id` ASC));

CREATE TABLE `datawarehouse`.`us2_authnet_shipping_address` (
  `authnet_shipping_address_id` INT NOT NULL AUTO_INCREMENT,
  `customer_profile_id` INT NOT NULL,
  `shipping_address_id` INT NOT NULL,
  `description` VARCHAR(45) NULL,
  `active_yn` CHAR(1) NOT NULL DEFAULT 'Y',
  PRIMARY KEY (`authnet_shipping_address_id`),
  INDEX `customer_profile_id` (`customer_profile_id` ASC),
  INDEX `shipping_address_id` (`shipping_address_id` ASC));

DROP TABLE `datawarehouse`.`us2_authnet_transaction`;
CREATE TABLE `datawarehouse`.`us2_authnet_transaction` (
  `authnet_transaction_id` INT NOT NULL AUTO_INCREMENT,
  `order_id` INT NOT NULL,
  `transaction_id` VARCHAR(45) NOT NULL,
  `transaction_type` ENUM('AUTH','AUTH_CAPTURE','CAPTURE','PRIOR','REFUND','VOID') NOT NULL,
  `customer_profile_id` INT NULL,
  `payment_profile_id` INT NULL,
  `shipping_address_id` INT NULL,
  `response_code` VARCHAR(10) NOT NULL,
  `transaction_timestamp` TIMESTAMP NULL,
  PRIMARY KEY (`authnet_transaction_id`),
  INDEX `order_id` (`order_id` ASC),
  INDEX `customer_profile_id` (`customer_profile_id` ASC));
