- entityDefinitions:
  - IDM_LoginPage: '{2193a8f1-c8ac-4b85-bc0c-f9c5b47e2e8d}'
  
  - IDM_LoginPageResponse: '{1d2448c3-d37e-496e-9114-4aae8daff077}'
  - IDMB_LoginPageResponse: '{9ceb0dc5-3601-4fe5-aa5b-1f11990cbc29}'

  - IDM_LoginPageResponseUnauthorized: '{1ee3e6aa-36e9-4355-abfa-82e8b52a680d}'
  - IDMB_LoginPageResponseUnauthorized: '{955f4980-e7e6-4547-ba7a-c1941650bc1b}'
  
  - IDM_LoginPagePRU: '{880789c8-1f61-4a95-a693-971bdf96dcd1}'
  - IDI_SystemUpdateRoutine_LoginUser: '{f36f8f87-0d2b-4e62-b85f-abb7e94d952c}'

  - IDM_User__update__Login: '{e01638d0-0101-45e3-8673-e15a3b192733}'
  - IDMB_User__update__Login: '{3a9ad7fd-f90d-4b4b-aaf5-93e7710f34d2}'

- library: '&IDL_MochaBaseSystem;'
  instances:
  - buildUIResponseMethod: '&IDM_LoginPageResponse;'
    # usesExecutableReturningElement: '&IDE_BuildAttributeMethod_View;'
    targetUrl: '~/d/home.htmld'
    targetUrlAttributeId: '&IDA_ReferralURL;'
    # FIXME!: this should trigger a write user session, then redirect to home page

  - buildUIResponseMethod: '&IDM_LoginPageResponseUnauthorized;'
    # usesExecutableReturningElement: '&IDE_BuildAttributeMethod_View;'
    targetUrl: '~/d/logout.htmld?reason=AuthenticationFailure'
    # FIXME!: this should trigger a write user session, then redirect to home page

  - buildResponseMethodBinding: '&IDMB_LoginPageResponse;'
    executesMethod: '&IDM_LoginPageResponse;'
    trueConditions:
    - instance: '&IDMB_User__is__Logged_In;'

  - buildResponseMethodBinding: '&IDMB_LoginPageResponseUnauthorized;'
    executesMethod: '&IDM_LoginPageResponseUnauthorized;'
    falseConditions:
    - instance: '&IDMB_User__is__Logged_In;'

  - controlTransactionMethod: '&IDM_LoginPage;'
    forClassId: '&IDC_Tenant;'
    verb: ''
    name: 'Login Page'
    buildsResponseWithBRMB:
    - instance: '&IDMB_LoginPageResponse;'
    - instance: '&IDMB_LoginPageResponseUnauthorized;'
    
  - systemUpdateRoutine: '&IDI_SystemUpdateRoutine_LoginUser;'
    name: 'Log in user'

  - executeUpdateMethodBinding: '&IDMB_User__update__Login;'
    executesMethod: '&IDM_User__update__Login;'

  # !!! FIXME !!! implement *** ALL *** of this and get it out of the PHP !!!
  - processRelatedUpdatesMethod: '&IDM_LoginPagePRU;'
    name: 'Login Page PRU'
    processesForClass: '&IDC_UserLogin;'
    static: yes
    usesExecutableForPUMB:
    # - instance: '&IDMB_User__update__Login;'
    - type: '&IDC_UpdateBySystemRoutineMethod;'
      globalIdentifier: '&IDM_User__update__Login;'
      forClassId: '&IDC_User;'
      verb: 'update'
      name: 'User Login and Session Credentials'
      static: yes
      systemUpdateRoutineId: '&IDI_SystemUpdateRoutine_LoginUser;'
      # comment: 'Calls into the OMS system update routine to save user login details. The resulting login token can be accessed with `OMS@get User Login Token(GAS)*S(public)`.'
  
    # - type: 'assignAttributeMethod'
    #   globalIdentifier: '{710f1b81-edf6-423d-bb49-423b814dd1de}'
    #   usesExecutableReturningAttribute: '&IDMB_User_Login__get__New_Randomly_Generated_Login_Token;' # GAS - generates a new randomly-generated login token via system routine
    #   assignsAttribute: '&IDA_Token;'

    # - type: 'assignAttributeMethod'
    #   globalIdentifier: '{9d88fce8-c566-4e0e-8c67-ac7130d3cbf2}'
    #   usesExecutableReturningAttribute: '&IDMB_OMS__get__Processing_User_IP_Address;' # GAS - get IP address of session user
    #   assignsAttribute: '&IDA_IPAddress;'

    # - type: 'assignRelationshipMethod'
    #   globalIdentifier: '{71d7b2ab-8d6a-44ba-a184-a605e240345f}'
    #   usesExecutableReturningInstanceSet: '&IDMB_User__get__User_by_User_Name_parm;' # GRS
    #   assignsRelationshipId: '&IDR_User_Login__has__User;'

  - element: '&IDE_LoginPageSubedit;'
    name: login page subedit
    moduleId: '&IDI_Module_MochaBaseSystem;'
    processedByCTMethod: '&IDM_LoginPage;'
    processedByPRUMethod: '&IDM_LoginPagePRU;'
    elementContents:
    - instance: '{4a827e38-e07a-4b8b-a19f-9217299f5c45}'
    - instance: '{c67f305e-bd4d-4628-816b-55fb85ea1b67}'
    - instance: '{51b51be3-44fd-48f1-971f-682aee0a6132}'
    - instance: '{684f1e03-9ecd-43d5-8aca-dcf5b84c71f8}'

  - file: '&IDI_File_SignonLogo;'
    name: 'Signon Logo'
    # use ' base64 -w 0 < file.svg | xc ' to copy base64 converted file
    #data: '[encoded data, 9412 characters]'
    data: '[encoded data, 10756 characters]'
    
    # FIXME! :: Define an embedded MCX resource like this:
    #data:
    #  resource: ''
    #  encoding: 'base64'
    contentType: 'image/svg+xml'
    contentEncoding: 'base64'
    # emits "background-image: url('data:$contentType;$contentEncoding,$data');"

  - textAttribute:      '&IDA_LoginPageInstructions;'
    name: 'Login Page Instructions'
    index: 1034
    value: 'Please enter your user name and password to log in to this system.'
    translations:
      - relationship: '&IDR_Translatable__has__Translation;'
        values:
          - language: '&IDI_Language_English;'
          - value: 'Login Page Instructions'
    
  - elementContent: '{4a827e38-e07a-4b8b-a19f-9217299f5c45}'
    defaultDataType: '&IDA_LoginPageInstructions;'
    order: b
    displayOptions:
    - instance: '&IDI_DisplayOption_DoNotShowLabel;'
    - instance: '&IDI_DisplayOption_NotEnterable;'
    - instance: '&IDI_DisplayOption_WideText;'

  - elementContent: '{c67f305e-bd4d-4628-816b-55fb85ea1b67}'
    defaultDataType: '&IDA_UserName;'
    order: c
    label: 'User name'
    displayOptions:
    - instance: '&IDI_DisplayOption_Required;'

  - elementContent: '{51b51be3-44fd-48f1-971f-682aee0a6132}'
    defaultDataType: '&IDA_Password;'
    order: d
    displayOptions:
    - instance: '&IDI_DisplayOption_Required;'
    - instance: '&IDI_DisplayOption_ObscuredText;'

  - elementContent: '{684f1e03-9ecd-43d5-8aca-dcf5b84c71f8}'
    defaultDataType: '&IDA_UserNameOrPasswordIncorrectMessage;'
    order: e
    displayOptions:
    - instance: '&IDI_DisplayOption_DoNotShowLabel;'
    - instance: '&IDI_DisplayOption_DoNotShow;'
    - instance: '&IDI_DisplayOption_NotEnterable;'
    - instance: '&IDI_DisplayOption_WideText;'
