#!/usr/bin/python3
#======================================================================================
# The Employee class - 
# hiding the attributes, and providing getters and setters
#======================================================================================
class Employee:

    __companyName   = "XYZ inc."                      # static attributes
    __employeeCount = 0                               # belong to the class as a whole


    def __init__(self, title,last,first,sex,old):     # constructor
        
        self.__position  = title                      # instance attributes
        self.__lastname  = last                       # belong to each object
        self.__firstname = first
        self.__sex       = sex
        self.__age       = old
        
        Employee.__employeeCount += 1;


    @staticmethod
    def getCompanyName() :                              # static getter method
        return (Employee.__companyName)                 

    @staticmethod
    def getEmployeeCount() :                            # static getter method
        return (Employee.__employeeCount)               

    @staticmethod 
    def setCompanyName(newname) :                       # static setter method
        Employee.__companyName = newname               

    @staticmethod                                       
    def companyInfo() :                                 
        print("Company    " , Employee.__companyName)
        print("Empl count " , Employee.__employeeCount)
#or     print("Empl count " , Employee.getEmployeeCount())


    def getPosition(self) :                             # instance getter method
        return (self.__position)

    def getLastname(self) :                             # instance getter method
        return (self.__lastname)

    def getFirstname(self) :                            # instance getter method
        return (self.__firstname)

    def getSex(self) :                                  # instance getter method
        return (self.__sex)

    def getAge(self) :                                  # instance getter method
        return (self.__age)

    def setPosition(self, title) :                      # instance setter method
        self.__position = title

    def setLastname(self, last) :                       # instance setter method
        self.__lastname = last

    def setFirstname(self, first) :                     # instance setter method
        self.__Firstname = first

    def setSex(self, sex) :                             # instance setter method
        self.__sex = sex

    def setAge(self, old) :                             # instance setter method
        self.__age = old

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


    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 (class) - using the getter and setters
#======================================================================================

class EmployeeUse:

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

#   co    = Employee.__companyName                  #I can no longer do this
#   count = Employee.__employeeCount

    co    = Employee.getCompanyName()               #I must call the getter method
    count = Employee.getEmployeeCount() 

    Employee.companyInfo()

    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                          #I can no longer do this
    fname = e1.getFirstname()                       #I must call the getter method
    print("First Name: " + fname)                   #prints  First Name: Sam

#   x.firstname = "Harry"                           #I can no longer do this
#   x.lastname  = "Potter"
    x.setFirstname("Harry")                         #I must call the setter method
    x.setLastname("Potter")

    print("After change: " + x.getFirstname() +" "+ x.getLastname())     #replaced with getter methods


    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 no longer do this
                                                   #there is no setter method for 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
#=================================================================================