<?xml version="1.0" encoding="UTF-8"?>
<OfficeApp
  xmlns="http://schemas.microsoft.com/office/appforoffice/1.1"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:bt="http://schemas.microsoft.com/office/officeappbasictypes/1.0"
  xmlns:mailappor="http://schemas.microsoft.com/office/mailappversionoverrides/1.0"
  xsi:type="MailApp">

  <!-- Basic Settings -->
  <Id>fa8aa40f-2133-4a67-8fcb-b7030f70cb15</Id>
  <Version>2.0.0.0</Version>
  <ProviderName>JQuad</ProviderName>
  <DefaultLocale>en-US</DefaultLocale>
  <DisplayName DefaultValue="JQuad AI Assistant"/>
  <Description DefaultValue="JQuad's AI-powered email assistant with intelligent agent service integration"/>
  <IconUrl DefaultValue="https://agent.jquad.rocks/assets/jquad-logo-64.png"/>
  <HighResolutionIconUrl DefaultValue="https://agent.jquad.rocks/assets/jquad-logo-128.png"/>
  <SupportUrl DefaultValue="https://jquad.rocks"/>

  <!-- Domains -->
  <AppDomains>
    <AppDomain>https://agent.jquad.rocks</AppDomain>
    <AppDomain>https://jquad.rocks</AppDomain>
    <AppDomain>https://keycloak.jquad.rocks</AppDomain>
  </AppDomains>

  <!-- Hosts -->
  <Hosts>
    <Host Name="Mailbox"/>
  </Hosts>

  <!-- Requirements -->
  <!-- Note: Requirement set 1.5 for Exchange 2019 compatibility. Attachment content requires 1.8 (Exchange Online only) -->
  <Requirements>
    <Sets>
      <Set Name="Mailbox" MinVersion="1.5"/>
    </Sets>
  </Requirements>

  <!-- Form Settings -->
  <FormSettings>
    <Form xsi:type="ItemRead">
      <DesktopSettings>
        <SourceLocation DefaultValue="https://agent.jquad.rocks/taskpane.html"/>
        <RequestedHeight>450</RequestedHeight>
      </DesktopSettings>
    </Form>
  </FormSettings>

  <!-- Permissions -->
  <!-- ReadWriteMailbox required for EWS makeEwsRequestAsync (attachment content retrieval on on-prem Exchange) -->
  <Permissions>ReadWriteMailbox</Permissions>

  <!-- Rules for activation -->
  <Rule xsi:type="RuleCollection" Mode="Or">
    <Rule xsi:type="ItemIs" ItemType="Message" FormType="Read"/>
    <Rule xsi:type="ItemIs" ItemType="Message" FormType="Edit"/>
  </Rule>

  <!-- Version Overrides for modern features -->
  <VersionOverrides xmlns="http://schemas.microsoft.com/office/mailappversionoverrides" xsi:type="VersionOverridesV1_0">
    <VersionOverrides xmlns="http://schemas.microsoft.com/office/mailappversionoverrides/1.1" xsi:type="VersionOverridesV1_1">
      <!-- Note: Requirement set 1.5 for Exchange 2019 compatibility. Attachment content requires 1.8 (Exchange Online only) -->
      <Requirements>
        <bt:Sets DefaultMinVersion="1.5">
          <bt:Set Name="Mailbox"/>
        </bt:Sets>
      </Requirements>

      <!-- Hosts -->
      <Hosts>
        <Host xsi:type="MailHost">
          <!-- Desktop Form Factor -->
          <DesktopFormFactor>
            <!-- Function File -->
            <FunctionFile resid="Commands.Url"/>

            <!-- Extension Points -->

            <!-- Message Read Command Surface -->
            <ExtensionPoint xsi:type="MessageReadCommandSurface">
              <OfficeTab id="TabDefault">
                <Group id="msgReadGroup">
                  <Label resid="GroupLabel"/>

                  <!-- Main Task Pane Button -->
                  <Control xsi:type="Button" id="msgReadOpenPaneButton">
                    <Label resid="TaskpaneButtonLabel"/>
                    <Supertip>
                      <Title resid="TaskpaneButtonLabel"/>
                      <Description resid="TaskpaneButtonTooltip"/>
                    </Supertip>
                    <Icon>
                      <bt:Image size="16" resid="Icon.16x16"/>
                      <bt:Image size="32" resid="Icon.32x32"/>
                      <bt:Image size="80" resid="Icon.80x80"/>
                    </Icon>
                    <Action xsi:type="ShowTaskpane">
                      <SourceLocation resid="Taskpane.Url"/>
                    </Action>
                  </Control>
                </Group>
              </OfficeTab>
            </ExtensionPoint>

            <!-- Message Compose Command Surface -->
            <ExtensionPoint xsi:type="MessageComposeCommandSurface">
              <OfficeTab id="TabDefault">
                <Group id="msgComposeGroup">
                  <Label resid="GroupLabel"/>

                  <!-- Main Task Pane Button -->
                  <Control xsi:type="Button" id="msgComposeOpenPaneButton">
                    <Label resid="TaskpaneButtonLabel"/>
                    <Supertip>
                      <Title resid="TaskpaneButtonLabel"/>
                      <Description resid="TaskpaneButtonTooltip"/>
                    </Supertip>
                    <Icon>
                      <bt:Image size="16" resid="Icon.16x16"/>
                      <bt:Image size="32" resid="Icon.32x32"/>
                      <bt:Image size="80" resid="Icon.80x80"/>
                    </Icon>
                    <Action xsi:type="ShowTaskpane">
                      <SourceLocation resid="Taskpane.Url"/>
                    </Action>
                  </Control>
                </Group>
              </OfficeTab>
            </ExtensionPoint>

          </DesktopFormFactor>
        </Host>
      </Hosts>

      <!-- Resources -->
      <Resources>
        <bt:Images>
          <bt:Image id="Icon.16x16" DefaultValue="https://agent.jquad.rocks/assets/jquad-logo-16.png"/>
          <bt:Image id="Icon.32x32" DefaultValue="https://agent.jquad.rocks/assets/jquad-logo-32.png"/>
          <bt:Image id="Icon.80x80" DefaultValue="https://agent.jquad.rocks/assets/jquad-logo-80.png"/>
        </bt:Images>
        <bt:Urls>
          <bt:Url id="Commands.Url" DefaultValue="https://agent.jquad.rocks/commands.html"/>
          <bt:Url id="Taskpane.Url" DefaultValue="https://agent.jquad.rocks/taskpane.html"/>
        </bt:Urls>
        <bt:ShortStrings>
          <bt:String id="GroupLabel" DefaultValue="JQuad AI"/>
          <bt:String id="TaskpaneButtonLabel" DefaultValue="JQuad AI"/>
        </bt:ShortStrings>
        <bt:LongStrings>
          <bt:String id="TaskpaneButtonTooltip" DefaultValue="Open JQuad AI Assistant for intelligent email processing"/>
        </bt:LongStrings>
      </Resources>

      <!-- WebApplicationInfo for Microsoft Graph API (NAA + file uploads) -->
      <WebApplicationInfo>
        <Id>de069e0b-5fe0-43f5-91b3-f14c6a27ff87</Id>
        <Resource>api://agent.jquad.rocks/de069e0b-5fe0-43f5-91b3-f14c6a27ff87</Resource>
        <Scopes>
          <Scope>openid</Scope>
          <Scope>profile</Scope>
          <Scope>Mail.Read</Scope>
          <Scope>Mail.Read.Shared</Scope>
          <Scope>Files.ReadWrite.All</Scope>
          <Scope>Sites.ReadWrite.All</Scope>
        </Scopes>
      </WebApplicationInfo>
    </VersionOverrides>
  </VersionOverrides>
</OfficeApp>