CREATE TABLE ipad_request_types (
	id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
	name VARCHAR(255) UNIQUE NOT NULL,
	code VARCHAR(16) UNIQUE NOT NULL
) ENGINE=InnoDB;

CREATE TABLE ipad_replacement_reasons (
	id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
	name VARCHAR(255) UNIQUE NOT NULL,
	code VARCHAR(16) UNIQUE NOT NULL
) ENGINE=InnoDB;

CREATE TABLE ipad_accessories (
	id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
	name VARCHAR(255) UNIQUE NOT NULL,
	code VARCHAR(16) UNIQUE NOT NULL
) ENGINE=InnoDD;

CREATE TABLE ipad_requests (
	id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
	request_id INT NOT NULL,
	request_type_id INT NOT NULL,
	replacement_reason_id INT DEFAULT NULL,
	new_sim_required TINYINT DEFAULT 0,
	mobile_number VARCHAR(16) DEFAULT NULL,
	approver_service_number INT NOT NULL,
	FOREIGN KEY fk_request (request_id) REFERENCES requests (id),
	FOREIGN KEY fk_request_type (request_type_id) REFERENCES ipad_request_types (id),
	FOREIGN KEY fk_replacement_reason (replacement_reason_id) REFERENCES ipad_replacement_reasons (id),
	FOREIGN KEY fk_approver (approver_service_number) REFERENCES users (service_number)
) ENGINE=InnoDB;

CREATE TABLE ipad_request_accessories (
	ipad_request_id INT NOT NULL,
	accessory_id INT NOT NULL,
	FOREIGN KEY fk_ipad_request (ipad_request_id) REFERENCES ipad_requests (id),
	FOREIGN KEY fk_accessory (accessory_id) REFERENCES ipad_accessories (id)
) ENGINE=InnoDB;