{
  "pluginAlias": "LGAc",
  "pluginType": "platform",
  "singular": true,
  "customUi": true,
  "schema": {
    "auth_mode": {
      "title": "Auth Mode",
      "type": "string",
      "default": "account",
      "oneOf": [
        {
          "title": "LG Account",
          "enum": [
            "account"
          ]
        },
        {
          "title": "Token",
          "enum": [
            "token"
          ]
        }
      ]
    },
    "username": {
      "title": "Username",
      "type": "string",
      "condition": {
        "functionBody": "return model.auth_mode === 'account';"
      }
    },
    "password": {
      "title": "Password",
      "type": "string",
      "condition": {
        "functionBody": "return model.auth_mode === 'account';"
      }
    },
    "refresh_token": {
      "title": "Refresh Token",
      "type": "string",
      "condition": {
        "functionBody": "return model.auth_mode === 'token';"
      }
    },
    "country": {
      "title": "Country",
      "type": "string",
      "default": "US",
      "required": true
    },
    "language": {
      "title": "Language",
      "type": "string",
      "default": "en-US",
      "required": true
    },
    "devices": {
      "title": "Devices",
      "description": "leave it empty to enable all device in account",
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "id": {
            "title": "Device ID",
            "type": "string",
            "required": true
          },
          "name": {
            "title": "Device Name",
            "type": "string"
          },
          "type": {
            "title": "Device Type",
            "type": "string",
            "enum": [
              "AC"
            ],
            "condition": {
              "functionBody": "return false;"
            }
          },
          "serial_number": {
            "title": "Serial Number (optional)",
            "type": "string"
          },
          "ac_fan_control": {
            "title": "Enable FAN control",
            "type": "boolean"
          },
          "ac_led_control": {
            "title": "Enable led panel control",
            "type": "boolean"
          },
          "ac_jetmode_control": {
            "title": "Enable separate jetmode control",
            "type": "boolean"
          },
          "ac_comfort_sleep_control": {
            "title": "Enable comfort sleep control",
            "type": "boolean"
          }
        }
      }
    }
  },
  "layout": [
    "auth_mode",
    {
      "type": "flex",
      "flex-flow": "row wrap",
      "items": [
        "username",
        {
          "key": "password",
          "type": "password"
        }
      ]
    },
    "refresh_token",
    {
      "type": "flex",
      "flex-flow": "row wrap",
      "items": [
        "country",
        "language"
      ]
    }, 
    {
      "key": "devices",
      "type": "tabarray",
      "title": "{{ value.name || 'new device' }}",
      "items": [
        "devices[].name",
        "devices[].id",
        "devices[].type",
        "devices[].serial_number",
        {
          "key": "devices[]",
          "type": "fieldset",
          "title": "{{ value.title }}",
          "items": [
            {
              "type": "fieldset",
              "title": "Air conditioner specific settings",
              "description": "Configure AC device settings.",
              "expandable": true,
              "expanded": false,
              "items": [
                "devices[].ac_fan_control",
                "devices[].ac_led_control",
                "devices[].ac_jetmode_control",
                "devices[].ac_comfort_sleep_control"
              ],
              "condition": {
                "functionBody": "return model.devices && model.devices[arrayIndices] && ['AC'].includes(model.devices[arrayIndices].type);"
              }
            }
          ]
        }
      ]
    }
  ]
}
