#!/usr/bin/python3.6

import pyorient

def create_user_class(client):
    print('Creating the class User')
    client.command('CREATE CLASS User EXTENDS V')
    print('Add the followings properties to the User:')
    print('- firstName')
    client.command('CREATE PROPERTY User.FirstName STRING')
    client.command('ALTER PROPERTY User.FirstName MANDATORY TRUE')
    print('- LastName')
    client.command('CREATE PROPERTY User.LastName STRING')
    client.command('ALTER PROPERTY User.LastName MANDATORY TRUE')
    print('- DateOfBirth')
    client.command('CREATE PROPERTY User.DateOfBirth DATE')
    client.command('ALTER PROPERTY User.DateOfBirth MANDATORY TRUE')
    print('- InsertionDate')
    client.command('CREATE PROPERTY User.InsertionDate DATE')
    client.command('ALTER PROPERTY User.InsertionDate MANDATORY TRUE')

def create_city_class(client):
    print('Creating the class City')
    client.command('CREATE CLASS City EXTENDS V')
    print('Add the followings properties to the City:')
    print('- Name')
    client.command('CREATE PROPERTY City.Name STRING')
    client.command('ALTER PROPERTY City.Name MANDATORY TRUE')
    print('- NameLowercase')
    client.command('CREATE PROPERTY City.NameLowercase STRING')
    client.command('ALTER PROPERTY City.NameLowercase MANDATORY TRUE')
    print('- InsertionDate')
    client.command('CREATE PROPERTY City.InsertionDate DATE')
    client.command('ALTER PROPERTY City.InsertionDate MANDATORY TRUE')

def create_school_class(client):
    print('Creating the class School')
    client.command('CREATE CLASS School EXTENDS V')
    print('Add the followings properties to the School:')
    print('- Name')
    client.command('CREATE PROPERTY School.Name STRING')
    client.command('ALTER PROPERTY School.Name MANDATORY TRUE')
    print('- NameLowercase')
    client.command('CREATE PROPERTY School.NameLowercase STRING')
    client.command('ALTER PROPERTY School.NameLowercase MANDATORY TRUE')
    print('- InsertionDate')
    client.command('CREATE PROPERTY School.InsertionDate DATE')
    client.command('ALTER PROPERTY School.InsertionDate MANDATORY TRUE')

def create_activity_and_domain_class(client):
    print('Creating the ActivityAndDomain class')
    client.command('CREATE CLASS ActivityAndDomain EXTENDS V')
    print('Add the followings properties to the ActivityAndDomain:')
    print('- Name')
    client.command('CREATE PROPERTY ActivityAndDomain.Name STRING')
    client.command('ALTER PROPERTY ActivityAndDomain.Name MANDATORY TRUE')
    print('- NameLowercase')
    client.command('CREATE PROPERTY ActivityAndDomain.NameLowercase STRING')
    client.command('ALTER PROPERTY ActivityAndDomain.NameLowercase MANDATORY TRUE')
    print('- InsertionDate')
    client.command('CREATE PROPERTY ActivityAndDomain.InsertionDate DATE')
    client.command('ALTER PROPERTY ActivityAndDomain.InsertionDate MANDATORY TRUE')

def create_skills_class(client):
    print('Creating the Skills class')
    client.command('CREATE CLASS Skills EXTENDS V')
    print('Add the followings properties to the Skills:')
    print('- Name')
    client.command('CREATE PROPERTY Skills.Name STRING')
    client.command('ALTER PROPERTY Skills.Name MANDATORY TRUE')
    print('- NameLowercase')
    client.command('CREATE PROPERTY Skills.NameLowercase STRING')
    client.command('ALTER PROPERTY Skills.NameLowercase MANDATORY TRUE')
    print('- InsertionDate')
    client.command('CREATE PROPERTY Skills.InsertionDate DATE')
    client.command('ALTER PROPERTY Skills.InsertionDate MANDATORY TRUE')

def create_offer_class(client):
    print('Creating the Offer class')
    client.command('CREATE CLASS Offer EXTENDS V')
    print('Add the followings properties to the Offer:')
    print('- Name')
    client.command('CREATE PROPERTY Offer.Name STRING')
    client.command('ALTER PROPERTY Offer.Name MANDATORY TRUE')
    print('- NameLowercase')
    client.command('CREATE PROPERTY Offer.NameLowercase STRING')
    client.command('ALTER PROPERTY Offer.NameLowercase MANDATORY TRUE')
    print('- InsertionDate')
    client.command('CREATE PROPERTY Offer.InsertionDate DATE')
    client.command('ALTER PROPERTY Offer.InsertionDate MANDATORY TRUE')
    print('- Description')
    client.command('CREATE PROPERTY Offer.Description STRING')
    client.command('ALTER PROPERTY Offer.Description MANDATORY TRUE')
    print('- GrossWage')
    client.command('CREATE PROPERTY Offer.GrossWage INTEGER')
    client.command('ALTER PROPERTY Offer.GrossWage MANDATORY TRUE')

def create_company_class(client):
    print('Creating the Company class')
    client.command('CREATE CLASS Company EXTENDS V')
    print('Add the followings properties to the Company:')
    print('- Name')
    client.command('CREATE PROPERTY Company.Name STRING')
    client.command('ALTER PROPERTY Company.Name MANDATORY TRUE')
    print('- NameLowercase')
    client.command('CREATE PROPERTY Company.NameLowercase STRING')
    client.command('ALTER PROPERTY Company.NameLowercase MANDATORY TRUE')
    print('- InsertionDate')
    client.command('CREATE PROPERTY Company.InsertionDate DATE')
    client.command('ALTER PROPERTY Company.InsertionDate MANDATORY TRUE')
    print('- Description')
    client.command('CREATE PROPERTY Company.Description STRING')
    client.command('ALTER PROPERTY Company.Description MANDATORY TRUE')
    print('- Siret')
    client.command('CREATE PROPERTY Company.Siret STRING')
    client.command('ALTER PROPERTY Company.Siret MANDATORY TRUE')
    print('- Siren')
    client.command('CREATE PROPERTY Company.Siren STRING')
    client.command('ALTER PROPERTY Company.Siren MANDATORY TRUE')

def create_hobbies_class(client):
    print('Creating the Hobbies class')
    client.command('CREATE CLASS Hobbies EXTENDS V')
    print('Add the followings properties to the Hobbies:')
    print('- Name')
    client.command('CREATE PROPERTY Hobbies.Name STRING')
    client.command('ALTER PROPERTY Hobbies.Name MANDATORY TRUE')
    print('- NameLowercase')
    client.command('CREATE PROPERTY Hobbies.NameLowercase STRING')
    client.command('ALTER PROPERTY Hobbies.NameLowercase MANDATORY TRUE')
    print('- InsertionDate')
    client.command('CREATE PROPERTY Hobbies.InsertionDate DATE')
    client.command('ALTER PROPERTY Hobbies.InsertionDate MANDATORY TRUE')

def create_edge_studied(client):
    print('Creating the Studied class extending edges')
    client.command('CREATE CLASS Studied EXTENDS E')
    print('Add the followings properties to the Studied:')
    print('- StartDate')
    client.command('CREATE PROPERTY Studied.StartDate DATE')
    client.command('ALTER PROPERTY Studied.StartDate MANDATORY TRUE')
    print('- EndDate')
    client.command('CREATE PROPERTY Studied.EndDate DATE')
    print('- Diploma')
    client.command('CREATE PROPERTY Studied.Diploma STRING')
    print('- StillStudying')
    client.command('CREATE PROPERTY Studied.StillStudying BOOLEAN')
    client.command('ALTER PROPERTY Studied.StillStudying MANDATORY TRUE')
    print('- InsertionDate')
    client.command('CREATE PROPERTY Studied.InsertionDate DATE')
    client.command('ALTER PROPERTY Studied.InsertionDate MANDATORY TRUE')

def create_edge_lives_in(client):
    print('Creating the LivesIn class extending Edges')
    client.command('CREATE CLASS LivesIn EXTENDS E')
    print('Add the followings properties to the LivesIn:')
    print('- InsertionDate')
    client.command('CREATE PROPERTY LivesIn.InsertionDate DATE')
    client.command('ALTER PROPERTY LivesIn.InsertionDate MANDATORY TRUE')

def create_edge_teach(client):
    print('Creating the Teach class extending Edges')
    client.command('CREATE CLASS Teach EXTENDS E')
    print('Add the followings properties to the Teach:')
    print('- InsertionDate')
    client.command('CREATE PROPERTY Teach.InsertionDate DATE')
    client.command('ALTER PROPERTY Teach.InsertionDate MANDATORY TRUE')

def create_edge_locates_in(client):
    print('Creating the LocatesIn class extending Edges')
    client.command('CREATE CLASS LocatesIn EXTENDS E')
    print('Add the followings properties to the LocatesIn:')
    print('- InsertionDate')
    client.command('CREATE PROPERTY LocatesIn.InsertionDate DATE')
    client.command('ALTER PROPERTY LocatesIn.InsertionDate MANDATORY TRUE')

def create_edge_works_in(client):
    print('Creating the WorksIn class extending Edges')
    client.command('CREATE CLASS WorksIn EXTENDS E')
    print('Add the followings properties to the WorksIn:')
    print('- InsertionDate')
    client.command('CREATE PROPERTY WorksIn.InsertionDate DATE')
    client.command('ALTER PROPERTY WorksIn.InsertionDate MANDATORY TRUE')

def create_edge_works_for(client):
    print('Creating the WorksFor class extending Edges')
    client.command('CREATE CLASS WorksFor EXTENDS E')
    print('Add the followings properties to the WorksFor:')
    print('- Position')
    client.command('CREATE PROPERTY WorksFor.Position STRING')
    client.command('ALTER PROPERTY WorksFor.Position MANDATORY TRUE')
    print('- InsertionDate')
    client.command('CREATE PROPERTY WorksFor.InsertionDate DATE')
    client.command('ALTER PROPERTY WorksFor.InsertionDate MANDATORY TRUE')

def create_edge_apply_for(client):
    print('Creating the ApplyFor class extending Edges')
    client.command('CREATE CLASS ApplyFor EXTENDS E')
    print('Add the followings properties to the ApplyFor:')
    print('- InsertionDate')
    client.command('CREATE PROPERTY ApplyFor.InsertionDate DATE')
    client.command('ALTER PROPERTY ApplyFor.InsertionDate MANDATORY TRUE')

def create_edge_master(client):
    print('Creating the Master class extending Edges')
    client.command('CREATE CLASS Master EXTENDS E')
    print('Add the followings properties to the Master:')
    print('- Level')
    client.command('CREATE PROPERTY Master.Level INTEGER')
    client.command('ALTER PROPERTY Master.Level MANDATORY TRUE')
    print('- InsertionDate')
    client.command('CREATE PROPERTY Master.InsertionDate DATE')
    client.command('ALTER PROPERTY Master.InsertionDate MANDATORY TRUE')

def creage_edge_cworks_in(client):
    print('Creating the CWorksIn class extending Edges')
    client.command('CREATE CLASS CWorksIn EXTENDS E')
    print('Add the followings properties to the CWorksIn:')
    print('- InsertionDate')
    client.command('CREATE PROPERTY CWorksIn.InsertionDate DATE')
    client.command('ALTER PROPERTY CWorksIn.InsertionDate MANDATORY TRUE')

def create_edge_require(client):
    print('Creating the Require class extending Edges')
    client.command('CREATE CLASS Require EXTENDS E')
    print('Add the followings properties to the Require:')
    print('- Level')
    client.command('CREATE PROPERTY Require.Level INTEGER')
    client.command('ALTER PROPERTY Require.Level MANDATORY TRUE')
    print('- InsertionDate')
    client.command('CREATE PROPERTY Require.InsertionDate DATE')
    client.command('ALTER PROPERTY Require.InsertionDate MANDATORY TRUE')

def create_edge_propose(client):
    print('Creating the Propose class extending Edges')
    client.command('CREATE CLASS Propose EXTENDS E')
    print('Add the followings properties to the Propose:')
    print('- InsertionDate')
    client.command('CREATE PROPERTY Propose.InsertionDate DATE')
    client.command('ALTER PROPERTY Propose.InsertionDate MANDATORY TRUE')

def create_edge_practice(client):
    print('Creating the Practice class extending Edges')
    client.command('CREATE CLASS Practice EXTENDS E')
    print('Add the followings properties to the Propose:')
    print('- InsertionDate')
    client.command('CREATE PROPERTY Practice.InsertionDate DATE')
    client.command('ALTER PROPERTY Practice.InsertionDate MANDATORY TRUE')
    print('- StartDate')
    client.command('CREATE PROPERTY Practice.StartDate DATE')
    client.command('ALTER PROPERTY Practice.StartDate MANDATORY TRUE')
    print('- EndDate')
    client.command('CREATE PROPERTY Practice.EndDate DATE')
    client.command('ALTER PROPERTY Practice.EndDate MANDATORY TRUE')
    

client = pyorient.OrientDB('localhost', 2424)
session_id = client.connect('root', 'root')

print('Opening session: ' + str(session_id))

print('Removing previous Square database...')
client.db_drop('Square')

if not client.db_exists('Square'):
    print('Creating the database: Square of type: ' + str(pyorient.DB_TYPE_GRAPH))
    client.db_create('Square', pyorient.DB_TYPE_GRAPH, pyorient.STORAGE_TYPE_PLOCAL)

print('Opening the DB: Square')
client.db_open('Square', 'root', 'root')
create_user_class(client)
create_city_class(client)
create_school_class(client)
create_activity_and_domain_class(client)
create_skills_class(client)
create_offer_class(client)
create_company_class(client)
create_hobbies_class(client)

print('CREATING THE EDGE CLASSES:')

create_edge_studied(client)
create_edge_lives_in(client)
create_edge_teach(client)
create_edge_locates_in(client)
create_edge_works_in(client)
create_edge_works_for(client)
create_edge_apply_for(client)
create_edge_master(client)
creage_edge_cworks_in(client)
create_edge_require(client)
create_edge_propose(client)
create_edge_practice(client)

client.close()