-- -----------------------------------------------------
-- Table `IOS_FEATURE`
-- -----------------------------------------------------
IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[IOS_FEATURE]') AND TYPE IN (N'U'))
CREATE TABLE IOS_FEATURE (
  ID INT NOT NULL IDENTITY,
  CODE VARCHAR(45) NOT NULL,
  NAME VARCHAR(100) NULL,
  DESCRIPTION VARCHAR(200) NULL,
  PRIMARY KEY (ID) 
);

-- -----------------------------------------------------
-- Table `IOS_DEVICE`
-- -----------------------------------------------------
IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[IOS_DEVICE]') AND TYPE IN (N'U'))
 CREATE  TABLE IOS_DEVICE (
  MOBILE_DEVICE_ID VARCHAR(45) NOT NULL,
  APNS_PUSH_TOKEN VARCHAR(100) NULL DEFAULT NULL,
  MAGIC_TOKEN VARCHAR(100) NULL DEFAULT NULL,
  MDM_TOKEN VARCHAR(100) NULL DEFAULT NULL,
  UNLOCK_TOKEN VARCHAR(2000) NULL DEFAULT NULL,
  CHALLENGE_TOKEN VARCHAR(45) NULL DEFAULT NULL,
  DEVICE_INFO VARCHAR(8000) NULL DEFAULT NULL,
  SERIAL VARCHAR(45) NULL DEFAULT NULL,
  PRODUCT VARCHAR(45) NULL DEFAULT NULL,
  IMEI VARCHAR(45) NULL DEFAULT NULL,
  VERSION VARCHAR(45) NULL DEFAULT NULL,
  MAC_ADDRESS VARCHAR(45) NULL DEFAULT NULL,
  DEVICE_NAME VARCHAR(100) NULL DEFAULT NULL,
  ICCID VARCHAR(45) NULL DEFAULT NULL,
  LATITUDE VARCHAR(45) NULL DEFAULT NULL,
  LONGITUDE VARCHAR(45) NULL DEFAULT NULL,
  PRIMARY KEY (MOBILE_DEVICE_ID)
);

-- -----------------------------------------------------
-- Table `IOS_DEVICE_PROFILE`
-- -----------------------------------------------------
CREATE TABLE IOS_DEVICE_PROFILE (
  ID INT NOT NULL IDENTITY,
  OPERATION_ID VARCHAR(10) NOT NULL,
  OPERATION_CODE VARCHAR(1000) NULL,
  PROFILE_ID VARCHAR(1000) NULL,
  DEVICE_IDENTIFICATION VARCHAR(300) DEFAULT NULL,
  PROPERTIES VARCHAR(max) DEFAULT NULL,
  PRIMARY KEY (ID)
);

-- -----------------------------------------------------
-- Table `IOS_ENROLLMENT_TOKEN`
-- -----------------------------------------------------
CREATE TABLE IOS_ENROLLMENT_TOKEN (
  TENANT_DOMAIN VARCHAR(255) NOT NULL,
  CHALLENGE_TOKEN VARCHAR(45) NOT NULL,
  DEVICE_ID VARCHAR(45) DEFAULT NULL,
  ACCESS_TOKEN VARCHAR(100) NOT NULL,
  REFRESH_TOKEN VARCHAR(100) NOT NULL,
  USERNAME VARCHAR(255) NOT NULL,
  CLIENT_CREDENTIALS VARCHAR(255) NOT NULL,
  UNIQUE (TENANT_DOMAIN, CHALLENGE_TOKEN),
  PRIMARY KEY (CHALLENGE_TOKEN)
);
