{
  "pluginAlias": "NestAccfactory",
  "pluginType": "platform",
  "singular": true,
  "schema": {
    "type": "object",
    "properties": {
      "name": {
        "title": "Name",
        "type": "string",
        "default": "NestAccfactory",
        "condition": "1=2"
      },
      "accounts": {
        "type": "array",
        "items": {
          "type": "object",
          "properties": {
            "name": {
              "type": "string",
              "placeholder": "Account description for configuration"
            },
            "type": {
              "type": "string",
              "default": "google",
              "enum": ["google", "nest"]
            },
            "access_token": {
              "type": "string",
              "placeholder": "See https://github.com/n0rt0nthec4t/homebridge-nest-accfactory/#nest-account"
            },
            "issueToken": {
              "type": "string",
              "placeholder": "See https://github.com/n0rt0nthec4t/homebridge-nest-accfactory/#google-account"
            },
            "cookie": {
              "type": "string",
              "placeholder": "See https://github.com/n0rt0nthec4t/homebridge-nest-accfactory/#google-account"
            },
            "fieldTest": {
              "type": "boolean",
              "default": false
            },
            "exclude": {
              "type": "boolean",
              "default": false
            }
          },
          "required": ["name", "type"],
          "allOf": [
            {
              "if": {
                "properties": {
                  "type": {
                    "const": "google"
                  }
                }
              },
              "then": {
                "required": ["issueToken", "cookie"]
              }
            },
            {
              "if": {
                "properties": {
                  "type": {
                    "const": "nest"
                  }
                }
              },
              "then": {
                "required": ["access_token"]
              }
            }
          ]
        }
      },
      "options": {
        "type": "object",
        "properties": {
          "debug": {
            "type": "boolean",
            "default": false
          },
          "eveHistory": {
            "type": "boolean",
            "default": true
          },
          "exclude": {
            "type": "boolean"
          },
          "ffmpegDebug": {
            "type": "boolean",
            "default": false
          },
          "ffmpegHWAccel": {
            "type": "boolean",
            "default": false
          },
          "ffmpegPath": {
            "type": "string",
            "default": "/usr/local/bin/ffmpeg"
          },
          "ffmpegTranscode": {
            "type": "boolean",
            "default": false
          },
          "logMotionEvents": {
            "type": "boolean",
            "default": true
          },
          "maxStreams": {
            "type": "number",
            "default": 2,
            "minimum": 1,
            "maximum": 4
          },
          "supportDump": {
            "type": "boolean",
            "default": false
          },
          "useNestAPI": {
            "type": "boolean"
          },
          "useGoogleAPI": {
            "type": "boolean"
          }
        }
      },
      "devices": {
        "type": "array",
        "items": {
          "title": "Device",
          "type": "object",
          "properties": {
            "serialNumber": {
              "type": "string",
              "placeholder": "Device serial number",
              "required": true
            },
            "name": {
              "title": "Name",
              "type": "string",
              "placeholder": "Device description for configuration"
            },
            "chimeSwitch": {
              "type": "boolean"
            },
            "doorbellCooldown": {
              "type": "string"
            },
            "eveHistory": {
              "type": "boolean"
            },
            "exclude": {
              "type": "boolean"
            },
            "external": {
              "type": "string"
            },
            "fanDuration": {
              "type": "string"
            },
            "ffmpegDebug": {
              "type": "boolean"
            },
            "ffmpegHWAccel": {
              "type": "boolean"
            },
            "ffmpegTranscode": {
              "type": "boolean"
            },
            "hotwaterBoostTime": {
              "type": "string"
            },
            "hotwaterMaxTemp": {
              "type": "string"
            },
            "hotwaterMinTemp": {
              "type": "string"
            },
            "humiditySensor": {
              "type": "boolean"
            },
            "localAccess": {
              "type": "boolean"
            },
            "logMotionEvents": {
               "type": "boolean"
            },
            "motionCooldown": {
              "type": "string"
            }
          }
        }
      },
      "homes": {
        "title": "Per Home configuration options",
        "type": "array",
        "items": {
          "title": "Home",
          "type": "object",
          "properties": {
            "name": {
              "title": "Home name",
              "type": "string",
              "required": true
            },
            "elevation": {
              "type": "number",
              "minimum": 0,
              "maximum": 8848
            },
            "exclude": {
              "type": "boolean"
            },
            "weather": {
              "type": "boolean"
            }
          }
        }
      }
    }
  },
  "layout": [
    {
      "type": "fieldset",
      "title": "Accounts",
      "description": "One or more accounts to connect to Google/Nest services. See plugin documentation for details on obtaining required credentials for each account type.",
      "expandable": true,
      "expanded": true,
      "items": [
        {
          "type": "array",
          "key": "accounts",
          "title": " ",
          "buttonText": "Add Account",
          "orderable": false,
          "arrayItemTitle": "{{value.name || 'Account'}}",
          "items": [
            { 
              "key": "accounts[].name", 
              "title": "Name"
            },
            {
              "key": "accounts[].type", 
              "title": "Type",
              "enumNames": ["Google", "Nest"],
              "oneOf": [
                {
                  "enum": ["google"]
                },
                {
                  "enum": ["nest"]
                }
              ]
            },
            { 
              "key": "accounts[].issueToken",
              "title": "Issue Token",
              "condition": {
                  "functionBody": "return model.accounts[arrayIndices] && model.accounts[arrayIndices].type === 'google';"
                }
            },
            { 
              "key": "accounts[].cookie",
              "title": "Cookie",
              "condition": {
                  "functionBody": "return model.accounts[arrayIndices] && model.accounts[arrayIndices].type === 'google';"
                }
            },
            { 
              "key": "accounts[].access_token",
              "title": "Access Token",
              "condition": {
                  "functionBody": "return model.accounts[arrayIndices] && model.accounts[arrayIndices].type === 'nest';"
                }
            },
            { 
              "key": "accounts[].fieldTest",
              "title": "Use Field Test API"
            },
            { 
              "key": "accounts[].exclude",
              "title": "Exclude Account"
            }
          ]
        }
      ]
    },
    {
      "type": "fieldset",
      "title": "Home Settings",
      "description": "Add and configure settings for specific Nest or Google homes.",
      "expandable": true,
      "expanded": false,
      "items": [
        {
          "type": "array",
          "title": "Homes",
          "key": "homes",
          "description": "Each entry applies to a home. The name must match the home name in the Nest or Google Home apps.",
          "buttonText": "Add Home",
          "orderable": false,
          "items": [
            {
              "key": "homes[].name",
              "title": "Home Name",
              "placeholder": "Must match the home name in the Nest or Google Home apps"
            },
            {
              "key": "homes[].weather",
              "title": "Enable Weather Station"
            },
            {
              "key": "homes[].elevation",
              "title": "Elevation",
              "condition": {
                "functionBody": "return (model && model.homes && model.homes[arrayIndices] && model.homes[arrayIndices].weather === true);"
              }
            },
            {
              "key": "homes[].exclude",
              "title": "Exclude All Devices from Home"
            }
          ]
        }
      ]
    },
    {
      "type": "fieldset",
      "title": "Device Settings",
      "description": "Configure global device settings or override them for specific devices.",
      "expandable": true,
      "expanded": false,
      "items": [
        {
          "key": "options.exclude",
          "title": "Exclude All Devices"
        },
        {
          "key": "options.eveHistory",
          "title": "Enable Eve History for All Devices"
        },
        {
          "type": "array",
          "title": "Device Overrides",
          "key": "devices",
          "description": "Override settings for specific devices using their serial number. Additional advanced options are available via manual configuration.",
          "buttonText": "Add Device Override",
          "orderable": false,
          "arrayItemTitle": "{{value.name || value.serialNumber || 'Device'}}",
          "items": [
            {
              "key": "devices[].serialNumber",
              "title": "Serial Number"
            },
            {
              "key": "devices[].name",
              "title": "Name"
            },
            {
              "key": "devices[].exclude",
              "title": "Exclude Device"
            },
            {
              "key": "devices[].eveHistory",
              "title": "Enable Eve History"
            }
          ]
        }
      ]
    },
    {
      "type": "fieldset",
      "title": "Options",
      "expandable": true,
      "expanded": false,
      "items": [
        {
          "key": "options.ffmpegPath",
          "title": "FFmpeg Binary Path"
        },
        {
          "key": "options.ffmpegHWAccel",
          "title": "Enable Video Hardware Acceleration"
        },
        {
          "key": "options.ffmpegTranscode",
          "title": "Enable Video Transcoding"
        },
        {
          "key": "options.maxStreams",
          "title": "Simultaneous Live Viewers per Camera"
        },
        {
          "key": "options.debug",
          "title": "Enable Verbose Logging"
        },
        {
          "key": "options.logMotionEvents",
          "title": "Enable Motion Event Logging"
        },
        {
          "key": "options.ffmpegDebug",
          "title": "Enable FFmpeg Debug Logging"
        },
        {
          "key": "options.supportDump",
          "title": "Enable Support Dump Logging",
          "description": "Enable detailed device data logging for troubleshooting. Only enable when requested as it may produce large logs."
        }
      ]
    }
  ]
}