from typing import List
from fastapi import APIRouter,Depends
from sqlalchemy.orm import Session
from app.api.customer_location import service
from app.database.main.mysql import get_db
from .schemas import TotalConsumptionResponse, customer_location_creat ,customerLocationResponse,customerLocationUpdate
from app.dependency.authantication import JWTPayloadSchema ,get_current_student

customer_location_router = APIRouter()

@customer_location_router.post("/customer_location", response_model_exclude_none=True)
async def create_customer_locatio(request: List[customer_location_creat],db: Session = Depends(get_db),token: JWTPayloadSchema = Depends(get_current_student)):
    return await service.Customer_location(db, token).create_customer_location(request)

@customer_location_router.get("/customer_location/group/{group_id}/total_consumption",response_model=TotalConsumptionResponse)
async def get_total_consumption_by_group(group_id: int,db: Session = Depends(get_db),token: JWTPayloadSchema = Depends(get_current_student)):
    return await service.Customer_location(db, token).get_total_potential_by_group(group_id)

@customer_location_router.get("/customer_location/get/{customer_location_id}", response_model=customerLocationResponse, response_model_exclude_none=True)
async def get_simulation(customer_location_id: int, db: Session = Depends(get_db), token: JWTPayloadSchema = Depends(get_current_student)):
    return await service.Customer_location(db, token).get_customer_location(customer_location_id)

@customer_location_router.get("/customer_location/group/{group_id}",response_model=list[customerLocationResponse],response_model_exclude_none=True)
async def get_customer_locations_by_group(group_id: int,db: Session = Depends(get_db),token: JWTPayloadSchema = Depends(get_current_student)):
    return await service.Customer_location(db, token).get_customer_locations_by_group(group_id)

@customer_location_router.put("/customer_location/update", response_model_exclude_none=True)
async def update_segment(request:customerLocationUpdate , db: Session = Depends(get_db),token: JWTPayloadSchema = Depends(get_current_student)):
    return await service.Customer_location(db,token).update_customer_location(request)

@customer_location_router.delete("/customer_location/delete/{customer_location_id}",response_model_exclude_none=True)
async def delete_catchment(customer_location_id: int,db: Session = Depends(get_db),token: JWTPayloadSchema = Depends(get_current_student)):
    return await service.Customer_location(db, token).delete_customer_location(customer_location_id)






