

from fastapi import APIRouter, Depends, Query

from sqlalchemy.ext.asyncio import AsyncSession
from apis.base import StandardResponse, standard_response
from db.database import get_db
from entity.device_scene_relation import DeviceSceneRelationInfo, DeviceSceneRelation

from services.device_scene_relation_service import DeviceSceneRelationService

router = APIRouter()


@router.get("/get_by_device", response_model=StandardResponse[DeviceSceneRelationInfo])
async def list_by_device(
        device_id: int,
        db: AsyncSession = Depends(get_db)):
    service = DeviceSceneRelationService(db)
    scene = await service.get_device_scene(device_id)
    return standard_response(data=scene)


@router.post("/update_by_device", response_model=StandardResponse[DeviceSceneRelation])
async def update_by_device(device_id: int, scene_id: int, range_points: str = None,
                     db: AsyncSession = Depends(get_db)):
    service = DeviceSceneRelationService(db)
    relation = await service.update_relation_by_device(device_id, scene_id,range_points)
    return standard_response(data=relation)
