'''
The submodule dedicated to handling just items
'''
from fastapi import APIRouter, Depends, HTTPException, status
from ..dependencies import get_token_header

router = APIRouter(
    prefix='/items',
    tags=['items'],
    dependencies=[Depends(get_token_header)],
    responses={404: {'description': 'Not found'}})

fake_item_db = {
    'plumbus': {'name': 'Plumbus'},
    'gun': {'name': 'Portal Gun'}}

@router.get('')
async def read_items():
    return fake_item_db

@router.get('/{item_id}')
async def read_item(item_id: str):
    if item_id not in fake_item_db:
        raise HTTPException(
            status_code=status.HTTP_404_NOT_FOUND,
            detail='Item not found')
    return {
        'name': fake_item_db[item_id]['name'], 
        'item_id': item_id}

@router.put('/{item_id}', tags=['custom'],
    responses={403: {'description': 'Operation forbidden'}})
async def update_item(item_id: str):
    if item_id != 'plumbus':
        raise HTTPException(
            status_code=status.HTTP_403_FORBIDDEN,
            detail='You can only update the item: plumbus')
    return {'item_id': item_id, 'name': 'The great Plumbus'}
