"""
    schema: platform-specific decoded status message
"""
# from . import full_message_schema, api
# from flask_restx import fields


gps_schema = {
    "type": "object",
    "properties": {
        "gps_source": {
            "type": "string",
            "description": "Source of gps position. E.g. USBL (external),"
            + "platform itself (internal)",
            "example": "internal",
        },
        "latitude_type": {
            "type": "string",
            "description": "TODO: Add description",
        },
        "longitude_type": {
            "type": "string",
            "description": "TODO: Add description",
        },
        "latitude": {
            "type": "number",
            "description": "Latitude in decimal degrees.",
            "example": 178.2,
        },
        "longitude": {
            "type": "number",
            "description": "Longitude in decimal degrees.",
            "example": -10.122,
        },
        "depth": {
            "type": "number",
            "description": "Target depth in metres",
            "example": 50,
            "default": 0,
        },
        "altitude": {
            "type": "number",
            "description": "Target altitude in metres",
            "example": 20,
        },
    },
    "required": [
        "gps_source",
        "latitude",
        "longitude",
    ],
}

sensor_schema = {
    "type": "object",
    "description": "Scanning sensor on platform available to be controlled by  the Autonomy Engine",
    "properties": {
        "sensor_serial": {
            "type": "string",
            "description": "serial number of sensor",
            "example": "mbes-002a",
        },
        "sensor_status": {
            "type": "boolean",
            "description": "Sensor switched on (True) or off (False)",
            "example": True,
        },
        "additional_data": {
            "type": "null",
            "description": "Any addition fields/data to be added here",
            "example": {"payload": [1.2, 434]},
        },
    },
    "required": [],
}

platform_status_message_schema = {
    "allOf": [{"$ref": "#/components/schemas/Message"}],
    "type": "object",
    "properties": {
        "platform_ID": {
            "type": "integer",
            "description": "Identifier for platform",
            "example": 1,
        },
        "platform_timestamp": {
            "type": "date-time",
            "decription": "Timestamp for onboard platform status message",
            "example": "2022-12-21T00:00:00Z",
        },
        "active": {
            "type": "boolean",
            "description": "When a platform is in deployment (executing a"
            + " mission plan) this should be True",
            "example": True,
        },
        "platform_state": {
            # TODO: Define dictionary with potential STATES of each platform
            "type": "string",
            "description": "Current state executed by platform. E.g. "
            + "STOP, IDLE, ABORT.",
            "example": "ABORT",
        },
        "autonomy_plan_ID": {
            "type": "integer",
            "description": "Last mission plan ID (according to Autonomy Engine's"
            + " mission plan number) executed by platform",
            "example": 1,
        },
        "mission_track_ID": {
            "type": "integer",
            "description": "Track number - stage in mission (e.g. "
            + "4 --> Waypoint 3 to Waypoint 4)",
            "example": 4,
        },
        "mission_action_ID": {
            "type": "integer",
            "description": "TODO: add description",
            "example": 1,
        },
        "range_to_go": {
            "type": "number",
            "description": "Estimated distance to reach next waypoint",
            "example": 124.3,
        },
        "speed_over_ground": {
            "type": "number",
            "description": "TODO: add description",
            "example": 124.3,
        },
        "water_current_velocity": {
            "type": "number",
            "description": "TODO: add description",
            "example": 124.3,
        },
        "thrust_applied": {
            "type": "number",
            "description": "TODO: Needs further consideration",
            "example": 124.3,
        },
        "health_status": {
            "type": "string",
            "description": "Health status extracted by respective platform "
            + "if any diagnosis is available to check sensors",
            "example": "Warning",
        },
        "gps_data": {
            "type": "array",
            "description": "position of platform",
            "items": gps_schema,
        },
        "localisation_error": {
            "type": "number",
            "description": "Localisation error at last USBL update.",
            "example": 0.000129,
        },
        "usbl_fix_seconds_ago": {
            "type": "number",
            "description": "USBL Fix received x second ago.",
            "example": 10.0,
        },
        "battery_remaining_capacity": {
            "type": "number",
            "description": "Battery remaining capacity % provided by respective",
            "example": 80.2,
        },
        "sensor_config": sensor_schema,
    },
    "required": [
        "platform_ID",
        "platform_timestamp",
        "gps_data",
        "battery_remaining_capacity",
    ],
}

# gps_schema = api.model(
#     "GPS",
#     {
#         "gps_source": fields.Float(  # TODO: TBD with partners
#             required=False,
#             description=(
#                 "Source of gps position. E.g. USBL (external),"
#                 + "platform itself (internal)"
#             ),
#             example="internal",
#         ),
#         "latitude_type": fields.String(
#             required=False,
#             description="",
#             example="",
#         ),
#         "longitude_type": fields.String(
#             required=False,
#             description="",
#             example="",
#         ),
#         "latitude": fields.Float(
#             required=False,
#             description="Latitude in <DEFINE UNITS>",
#             example="",
#         ),
#         "longitude": fields.Float(
#             required=False,
#             description="Longitude in <DEFINE UNITS>",
#             example="",
#         ),
#         "depth": fields.Float(
#             required=False,
#             description="Depth in <DEFINE UNITS>",
#             example="",
#         ),
#         "altitude": fields.Float(
#             required=False,
#             description="Altitude in <DEFINE UNITS>",
#             example="",
#         ),
#         # "gps_fix_seconds_ago"
#     },
# )

# sensor_schema = api.model(
#     "SensorSchema",
#     {
#         "sensor_ID": fields.Integer(
#             required=True,
#             description="unique identifier for platform",
#             example=2,
#         ),
#         "serial": fields.String(
#             required=False,
#             description="serial number of sensor",
#             example="mbes-001",
#         ),
#         "sensor_status": fields.Boolean(
#             required=False,
#             description="Sensor switched on (True) or off (False)",
#             example=True,
#         ),
#         "additional_data": fields.Raw(
#             required=False,
#             description="Any addition fields/data to be added here",
#         ),
#     },
# )

# platform_status_message_schema = api.model(
#     "platformStatusMessage",
#     {
#         "message": fields.Nested(
#             full_message_schema,
#             required=True,
#             description="Message header",
#         ),
#         "platform_ID": fields.Integer(
#             required=True,
#             description="unique identifier for platform",
#             example=1,
#         ),
#         "active": fields.Boolean(
#             required=False,
#             description="When a platform is in deployment (executing a"
#             + " mission plan) this should be True",
#             example=True,
#         ),
#         "platform_state": fields.String(
#             # TODO: Define dictionary with potential STATES of each platform
#             required=False,
#             description="Current state executed by platform. E.g. "
#             + "STOP, IDLE, ABORT.",
#             example="IDLE",
#         ),
#         "autonomy_plan_ID": fields.Integer(
#             required=False,
#             description="Last mission plan ID (according to Autonomy Engine's"
#             + " mission plan number) executed by platform",
#             example=1,
#         ),
#         "mission_track_ID": fields.Integer(
#             required=False,
#             description=(
#                 "Track number - stage in mission (e.g. "
#                 + "4 --> Waypoint 3 to Waypoint 4)"
#             ),
#             example=4,
#         ),
#         "mission_action_ID": fields.Integer(
#             required=False,
#             description="to add description",
#             example=1,
#         ),
#         "range_to_go": fields.Float(
#             required=False,
#             description="Estimated distance to reach next waypoint",
#             example=124.3,
#         ),
#         "speed_over_ground": fields.Float(
#             required=False,
#             description="",
#             example=124.3,
#         ),
#         "water_current_velocity": fields.Float(
#             required=False,
#             description="",
#             example=124.3,
#         ),
#         "thrust_applied": fields.Float(
#             required=False,
#             description="TODO: Needs further consideration",
#             example=124.3,
#         ),
#         "health_status": fields.String(
#             required=False,
#             description="Health status extracted by respective platform "
#             + "if any diagnosis available checks on sensors",
#             example="Warning",
#         ),
#         "gps_data": fields.List(
#             fields.Nested(gps_schema),  # TODO: TBD Do we want a list of
#             # gps readings to allow > 1 reading i.e. platform + usbl
#             required=True,
#             description="Metadata pf each platform",
#         ),
#         "localisation_error": fields.Float(
#             required=False,
#             description="Localisation error at last USBL update.",
#             example="",
#         ),
#         "usbl_fix_seconds_ago": fields.Float(
#             required=False,
#             description="",
#             example="",
#         ),
#         "battery_remaining_capacity": fields.Float(
#             required=True,
#             description="Battery remaining capacity % provided by respective"
#             + " platform/C2.",
#             example=80.0,
#         ),
#         "sensor_config": fields.Nested(
#             sensor_schema
#         ),  # TODO: TBD Do we want a list of sensors to allow > 1 sensor
#     },
# )

# # TBD: Do we append beacon positions with platform positions?