# Copyright 2019-2025 SURF.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from http import HTTPStatus

import structlog
from fastapi.routing import APIRouter

from orchestrator.schedules.service import add_scheduled_task_to_queue
from orchestrator.schemas.schedules import APSchedulerJobCreate, APSchedulerJobDelete, APSchedulerJobUpdate

logger = structlog.get_logger(__name__)

router: APIRouter = APIRouter()


@router.post("/", status_code=HTTPStatus.CREATED)
def create_scheduled_task(payload: APSchedulerJobCreate) -> dict[str, str]:
    """Create a scheduled task."""
    add_scheduled_task_to_queue(payload)
    return {"message": "Added to Create Queue", "status": "CREATED"}


@router.put("/", status_code=HTTPStatus.OK)
async def update_scheduled_task(payload: APSchedulerJobUpdate) -> dict[str, str]:
    """Update a scheduled task."""
    add_scheduled_task_to_queue(payload)
    return {"message": "Added to Update Queue", "status": "UPDATED"}


@router.delete("/", status_code=HTTPStatus.OK)
async def delete_scheduled_task(payload: APSchedulerJobDelete) -> dict[str, str]:
    """Delete a scheduled task."""
    add_scheduled_task_to_queue(payload)
    return {"message": "Added to Delete Queue", "status": "DELETED"}
