#!/usr/bin/python3 -s

# ************************************
# Copyright (C) 2021-2025 IoT.bzh Company *
# ************************************
# Contact: https://www.iot.bzh/licensing

# This file is part of the redpesk_lad module of the RedPesk project.

# $RP_BEGIN_LICENSE$
# Commercial License Usage
# Licensees holding valid commercial IoT.bzh licenses may use this file in \
# accordance with the commercial license agreement provided with the \
# Software or, alternatively, in accordance with the terms contained in \
# a written agreement between you and The IoT.bzh Company. For licensing terms \
# and conditions see https://www.iot.bzh/terms-conditions. For further \
# information use the contact form at https://www.iot.bzh/contact.

# GNU General Public License Usage
# Alternatively, this file may be used under the terms of the GNU General \
# Public license version 3. This license is as published by the Free Software \
# Foundation and appearing in the file LICENSE.GPLv3 included in the packaging \
# of this file. Please review the following information to ensure the GNU \
# General Public License requirements will be met \
# https://www.gnu.org/licenses/gpl-3.0.html.
# $RP_END_LICENSE$
# *****************************************

import asyncio
from aiohttp import web

from redpesk_lad.rp_lad_shared_constants import FULL_VERSION, APP_PORT
from redpesk_lad.rp_lad_logging import rp_lad_logger
from redpesk_lad.rp_lad_main import RPLADApp

if __name__ == "__main__":
    # Some logs to see what is running
    rp_lad_logger.info(f"[MAIN] Running 'redpesk-lad' with version '{FULL_VERSION}' on port '{APP_PORT}'")


    # Define the work queue that will be used to get the actions to do
    work_queue = asyncio.Queue()

    # Get the application
    rp_lad_app = RPLADApp(work_queue)

    if rp_lad_app is not None:
        # Run the HTTP API
        rp_lad_app.run()
        # End the app
        rp_lad_logger.info("[MAIN] Exiting LAD application")


    else:
        rp_lad_logger.error("[MAIN] No main app to run")
