from fastapi import Request,Depends, APIRouter, UploadFile,HTTPException,File
from app.db import Base,engine
from app.db.session import get_db
from app.db.crud import *
from app.db.schemas import AppBase, AppEdit, App,Kintone

platform_router = r = APIRouter()

@r.get(
    "/appsettings/{id}",
    response_model=App,
    response_model_exclude_none=True,
)
async def appsetting_details(
    request: Request,
    id: int,
    db=Depends(get_db),
):
    app = get_appsetting(db, id)
    return app
  

@r.post("/appsettings", response_model=App, response_model_exclude_none=True)
async def appsetting_create(
    request: Request,
    app: AppBase,
    db=Depends(get_db),
):
    return create_appsetting(db, app)


@r.put(
    "/appsettings/{id}", response_model=App, response_model_exclude_none=True
)
async def appsetting_edit(
    request: Request,
    id: int,
    app: AppEdit,
    db=Depends(get_db),
):
    return edit_appsetting(db, id, app)


@r.delete(
    "/appsettings/{id}", response_model=App, response_model_exclude_none=True
)
async def appsettings_delete(
    request: Request,
    id: int,
    db=Depends(get_db),
):

    return delete_appsetting(db, id)


@r.get(
    "/kintone/{type}",
    response_model=t.List[Kintone],
    response_model_exclude_none=True,
)
async def kintone_data(
    request: Request,
    type: int,
    db=Depends(get_db),
):
    kintone = get_kintones(db, type)
    return kintone