"""
    schemas: configuration sent to Autonomy Engine (i.e. during an emergency,
    if a platform needs to be removed from the mission planning)
"""

emergency_schema = {
    "type": "object",
    "properties": {
        "safe_command": {
            "type": "string",
            "enum": ["go_home", "abort_now", "stop_now", "surface_now"],
            "description": "Command/Action that is native to respective"
            + " partner's platform/C2",
            "example": "go_home",
        },
        "target_waypoint_latitude": {
            "type": "number",
            "format": "float",
            "description": "Y-coordinate safe place for respective platform",
            "example": 50.365,
        },
        "target_waypoint_longitude": {
            "type": "number",
            "format": "float",
            "description": "X-coordinate safe place for respective platform",
            "example": -7.432,
        },
        "target_depth": {
            "type": "number",
            "format": "float",
            "description": "Z-coordinate safe place for respective platform"
            + " . If platform to NOT stay at depth, key in `0.0`",
            "example": 10.0,
        },
    },
    "required": [
        "target_waypoint_latitude",
        "target_waypoint_longitude",
    ],
}

endurance_relative_water_speed_schema = {
    "type": "object",
    "properties": {
        "min_battery_rating": {
            "type": "number",
            "format": "float",
            "description": "Battery endurance rating during maximum speed usage (m/s)",
            "example": 3.32,
        },
        "max_battery_rating": {
            "type": "number",
            "format": "float",
            "description": "Battery endurance rating during maximum speed usage (m/s)",
            "example": 1.23,
        },
        "avg_battery_rating": {
            "type": "number",
            "format": "float",
            "description": (
                "Battery endurance rating during standard operational"
                + " speed usage (m/s)"
            ),
            "example": 1.9,
        },
    },
}


scan_sensor_schema = {
    "type": "object",
    "properties": {
        "sensor_type": {
            "type": "string",
            "description": "Unique identifier for this platform",
            "example": "MBES",
            "enum": ["SIDESCAN", "MBES"],
        },
        "warmup_time": {
            "type": "number",
            "format": "float",
            "description": "Warmup time (seconds) for sensor to start up.",
            "example": 180.0,
        },
        "swath_width": {
            "type": "number",
            "format": "float",
            "description": "Function of `target_altitude` for the platform's "
            + "swath width (in metres)",
            "example": 38.0,
        },
        "frequency": {
            "type": "number",
            "format": "float",
            "description": "Frequency of scanning sensor (in kHz)",
            "example": 700.0,
        },
        "angle": {
            "type": "number",
            "format": "float",
            "description": "Angle of range of swath width (in degrees)",
            "example": 140.0,
        },
    },
}


platform_schema = {
    "type": "object",
    "properties": {
        "operator": {
            "type": "string",
            "description": "Operator of platform",
            "example": "noc",
        },
        "platform_ID": {
            "type": "string",
            "description": "Unique identifier for this platform",
            "example": "reav-x-1",
        },
        "model": {
            "type": "string",
            "example": "reav",
        },
        "beacon_ID": {
            "type": "number",
            "description": "Unique identifier (number) for the beacon "
            + "associated to this platform",
            "example": 2407,
        },
        "active": {
            "type": "boolean",
            "description": "If platform is active = True, and inactive = False",
            "example": True,
        },
        "emergency": emergency_schema,
        "min_altitude": {
            "type": "number",
            "format": "float",
            "description": "Minimum altitude set for platform",
            "example": 15.2,
        },
        "min_velocity": {
            "type": "number",
            "format": "float",
            "description": "Minimum velocity set for platform",
            "example": 0.1,
        },
        "max_velocity": {
            "type": "number",
            "format": "float",
            "description": "Maximum velocity set for platform",
            "example": 0.9,
        },
        "target_altitude": {
            "type": "number",
            "format": "float",
            "description": "Target altitude set for platform. This affects swath width",
            "example": 15.0,
        },
        "turning_radius": {
            "type": "number",
            "format": "float",
            "description": "Turning radius of platform (in metres)",
            "example": 1.0,
        },
        "endurance_relative_to_water_speed": endurance_relative_water_speed_schema,
        "scan_sensor": scan_sensor_schema,
        "additional_data": {
            "description": "Any addition fields/data to be added here",
            "example": {"new_sensor_a": "test_sensor", "range": 10.0},
            "type": "object",
        },
    },
    "required": [
        "operator",
        "platform_ID",
        "active",
        "model",
    ],
}

squad_metadata_schema = {
    "type": "object",
    "properties": {
        "squad_ID": {
            "type": "integer",
            "description": "Identifier of given squad",
            "example": 23,
        },
        "no_of_platforms": {
            "type": "integer",
            "description": "Number of platforms",
            "example": 3,
        },
        "platforms": {
            "type": "array",
            "items": platform_schema,
            "description": "Squad consists of these platforms",
        },
        "squad_mission_type": {
            "type": "string",
            "enum": ["tracking", "survey", "inspection"],
            "description": "Mission of given squad: `tracking`, `survey`"
            + ", `inspection`",
            "example": "survey",
        },
    },
    "required": [
        "squad_ID",
        "no_of_platforms",
        "platforms",
        "squad_mission_type",
    ],
}

planning_configuration_schema = {
    "type": "object",
    "properties": {
        "message_type": {
            "type": "string",
            "description": "Type of message",
            "example": "planning_configuration",
            "enum": ["planning_configuration"],
        },
        "planning_config_ID": {
            "type": "integer",
            "description": "Unique identifier tagged to version of this"
            + " configuration plan",
            "example": 3,
        },
        "region_of_interest": {
            "type": "array",
            "items": {
                "$ref": "https://geojson.org/schema/Polygon.json",
            },
            "description": "Region of interest for the entire operation",
        },
        "exclusion_zones": {
            "type": "array",
            "items": {
                "$ref": "https://geojson.org/schema/Polygon.json",
            },
            "description": "Exclusion zones for all platforms",
        },
        "squads": {
            "type": "array",
            "items": squad_metadata_schema,
        },
    },
    "required": [
        "message_type",
        "planning_config_ID",
        "squads",
        "exclusion_zones",
        "region_of_interest",
    ],
}