# encoding: utf-8
require 'sequel'

# Database options
DB = Sequel.mysql2 'db_name', user:'user', password:'password', host:'localhost'

# Create users database: individuals or companies that have many clients
DB.create_table?(:users, engine: 'InnoDB') do 
	primary_key :id
	String :username, 	null: false, unique: true
	String :password_hash, 	null: false
	String :name
	String :vat, 		null: false, unique: true
	String :land_phone
	String :mobile_phone 
	String :email, 		null: false
	String :address, 	null: false
	String :city, 		null: false
	String :postal_code, 	null: false
	String :country, 	null: false
	String :role, 		default: 'user'
	DateTime :created_at,   default: Time.now
end

# Contracts table: Here the users can define their contracs
DB.create_table?(:contracts, engine: 'InnoDB') do
	primary_key :id
	Integer :user_id, null: false
	String  :name, null: false
	String  :description
	Numeric :cost, size: [10,2] , null: false
end

# Create clients database: each 'client' belongs to one 'user'
DB.create_table?(:clients, engine: 'InnoDB') do
	primary_key :id
	Integer :user_id, 	null: false
	Integer :contract_id, 	null: false
	String  :vpn_address
	String  :name, 		null: false
	String  :vat, 		null: false, unique: true
	String  :land_phone
	String  :mobile_phone 
	String  :email, 	null: false
	String  :address
	String  :city, 		null: false
	String  :postal_code, 	null: false
	String  :country, 	null: false
	Boolean  :not_paid, 	default: FALSE
	DateTime :created_at,   default: Time.now
	Boolean :review, 	default: FALSE
end

require_relative 'user'
require_relative 'client'
require_relative 'contract'
