#!/usr/bin/python3
#======================================================================================
# The Employee class 
#======================================================================================
class Employee:

    companyName   = "XYZ inc."                      # static variables
    employeeCount = 0                               # belong to the class as a whole


    def __init__(self, title,last,first,sex,old):   # constructor
        
        self.position   = title                     # instance variables
        self.lastname   = last                      # belong to each object
        self.firstname  = first
        self.sex        = sex
        self.age        = old
        
        Employee.employeeCount += 1;


    @staticmethod                                       # indicates static method
    def getEmployeeCount() :                            # static method
        return (Employee.employeeCount)                 # belongs to the class as a whole

    @staticmethod                                       # indicates static method
    def companyInfo() :                                 # static method
        print("Company    " , Employee.companyName)
        print("Empl count " , Employee.employeeCount)
#or     print("Empl count " , Employee.getEmployeeCount())


    def getFullname (self, salutation) :                              # instance method
        name  = salutation +" "+ self.firstname +" "+ self.lastname   # belongs to each object
        return (name)


    # Every object should ("best practice") have a __str__( ) method.
    # The __str__ ( ) method should return the content of the object in one long string 
    # If you use the object in any string context (e.g. printing), the __str__( ) method  
    #   will automatically be called.  We will cover this in more detail later

    def __str__(self) :                                             # instance method
        data  = "    Company "  + Employee.companyName + \
                "\t Position: " + self.position + \
                "\t Name: "     + self.firstname +  " " + self.lastname + \
                "\t Sex: "      + self.sex + \
                "\t Age: "      + str(self.age)
        return (data)



#======================================================================================
# The user program
#======================================================================================

print("Content-type: text/html \n")             #required HTTP response header


co    = Employee.companyName                    #access static field
count = Employee.employeeCount

Employee.companyInfo()                          #call a static method

e1 = Employee("Dir","Sultan","Sam","M",45)      #instantiate/create objects
e2 = Employee("Mgr","Smith","Mary","F",35)  
e3 = Employee("Sec","Stevens","Bob","M",28)
x  = Employee("???","Person","Mystery","",0)

fname = e1.firstname                            #access instance field
print("First Name: " + fname)                   #prints  First Name: Sam

x.firstname = "Harry"                           #changing instance fields
x.lastname  = "Potter"

print("After change: " + x.firstname +" "+ x.lastname)    #prints Harry Potter


count = Employee.getEmployeeCount( )           #call static method
print("Number of employees: ", count)          #prints  Number Employees: 4

name1 = e1.getFullname("Mr.")                  #call instance method 
print(name1)                                   #prints:  Mr. Sam Sultan

print(e2.getFullname("Ms."))                   #combining 2 previous. lines

print(e3.__str__())                            #call the __str__() method

print(x)                                       #when an obj. is used in string context
                                               #no need to say  .__str__( )
                                               
Employee.employeeCount += 10                   #I can destroy the integrity of the variable

print("Number of employees now:", Employee.employeeCount) 




                                               
                                               
#=== link to see the python code =================================================
import os, sys
sys.path.insert(0,'/home/s/sultans/web/python/demo')
import zCode                          #import func to display the Python code
filename = os.path.abspath(__file__)  #get absolute file name 
zCode.display(filename)               #call it
#=================================================================================