"""
Copyright (c) 2021 VMware, Inc.  All rights reserved. -- VMware Confidential

Dummy vmware-horizon-teams-optimization component.
"""

class VMwareHorizonTeamsOptimization(Installer):
   def InitializeQuestions(self, old, new, upgrade):
      if self.GetAnswer('teamsOptimizationEnable'):
         qlevel = 'CUSTOM'
      else:
         qlevel = 'REGULAR'

      self.AddMultiChoiceQuestion('YesNo',
                                  key='teamsOptimizationEnable',
                                  text='Media Optimization for Microsoft Teams',
                                  required=True,
                                  default='yes',
                                  footer='Enable Media Optimization for Microsoft Teams.',
                                  level=qlevel)

   def InitializeInstall(self, old, new, upgrade):
      if self.GetAnswer('teamsOptimizationEnable') == 'yes':
          self.AddTarget('File', 'lib/*', LIBDIR)
          self.SetPermission(LIBDIR/'vmware/view/vdpService/webrtcRedir/libwebrtc_sharedlib.so', BINARY)

      if (CONFDIR/'abortInstall').exists():
         raise InstallError('View abort install')

   def InitializeUninstall(self, old, new, upgrade):
      if (CONFDIR/'abortUninstall').exists():
         raise InstallError('View aborting uninstall')
      self.RunCommand('true', ignoreErrors=True)

   def PostInstall(self, old, new, upgrade):
      self.SetConfig('teamsOptimizationComponent', 'test')
      if self.GetAnswer('teamsOptimizationEnable') == 'yes':
         self.AddScanFile(LIBDIR/'vmware/view/vdpService/webrtcRedir/libwebrtc_sharedlib.so')

   def PostUninstall(self, old, new, upgrade):
      self.DelConfig('teamsOptimizationComponent')
      self.DelConfig('teamsOptimizationComponent')
