from fastapi import APIRouter
from api.v1.common.tenant_crud_routes import TenantCRUDRoutes
from . import dto, service

router = APIRouter(prefix="/units-of-measure",
                   tags=["a76.general_catalogs.units_of_measure"])

# ACE
ace_router = TenantCRUDRoutes(
    service=service.UnitOfMeasureACEService,
    create_schema=dto.UnitOfMeasureACECreate,
    update_schema=dto.UnitOfMeasureACEUpdate,
    response_schema=dto.UnitOfMeasureACEResponse,
    prefix="/ace",
    tags=["a76.general_catalogs.units_of_measure"],
    resource_name="UnitOfMeasureACE",
    id_name="id",
    enable_list=True,
    enable_filters=True,
    max_page_size=10000,
    # Permisos
    list_permissions=["cat_um_ace.view"],
    get_permissions=["cat_um_ace.view"],
    create_permissions=["cat_um_ace.create"],
    update_permissions=["cat_um_ace.edit"],
    delete_permissions=["cat_um_ace.delete"],
).router
router.include_router(ace_router)

# OMA
oma_router = TenantCRUDRoutes(
    service=service.UnitOfMeasureOMAService,
    create_schema=dto.UnitOfMeasureOMACreate,
    update_schema=dto.UnitOfMeasureOMAUpdate,
    response_schema=dto.UnitOfMeasureOMAResponse,
    prefix="/oma",
    tags=["a76.general_catalogs.units_of_measure"],
    resource_name="UnitOfMeasureOMA",
    id_name="id",
    enable_list=True,
    enable_filters=True,
    max_page_size=10000,
    # Permisos
    list_permissions=["cat_um_oma.view"],
    get_permissions=["cat_um_oma.view"],
    create_permissions=["cat_um_oma.create"],
    update_permissions=["cat_um_oma.edit"],
    delete_permissions=["cat_um_oma.delete"],
).router
router.include_router(oma_router)

# American
american_router = TenantCRUDRoutes(
    service=service.UnitOfMeasureAmericanService,
    create_schema=dto.UnitOfMeasureAmericanCreate,
    update_schema=dto.UnitOfMeasureAmericanUpdate,
    response_schema=dto.UnitOfMeasureAmericanResponse,
    prefix="/american",
    tags=["a76.general_catalogs.units_of_measure"],
    resource_name="UnitOfMeasureAmerican",
    id_name="id",
    enable_list=True,
    enable_filters=True,
    max_page_size=10000,
    # Permisos
    list_permissions=["cat_um_american.view"],
    get_permissions=["cat_um_american.view"],
    create_permissions=["cat_um_american.create"],
    update_permissions=["cat_um_american.edit"],
    delete_permissions=["cat_um_american.delete"],
).router
router.include_router(american_router)

# Customs
customs_router = TenantCRUDRoutes(
    service=service.UnitOfMeasureCustomsService,
    create_schema=dto.UnitOfMeasureCustomsCreate,
    update_schema=dto.UnitOfMeasureCustomsUpdate,
    response_schema=dto.UnitOfMeasureCustomsResponse,
    prefix="/customs",
    tags=["a76.general_catalogs.units_of_measure"],
    resource_name="UnitOfMeasureCustoms",
    id_name="id",
    enable_list=True,
    enable_filters=True,
    max_page_size=10000,
    # Permisos
    list_permissions=["cat_um_customs.view"],
    get_permissions=["cat_um_customs.view"],
    create_permissions=["cat_um_customs.create"],
    update_permissions=["cat_um_customs.edit"],
    delete_permissions=["cat_um_customs.delete"],
).router
router.include_router(customs_router)

# General
general_router = TenantCRUDRoutes(
    service=service.UnitOfMeasureGeneralService,
    create_schema=dto.UnitOfMeasureGeneralCreate,
    update_schema=dto.UnitOfMeasureGeneralUpdate,
    response_schema=dto.UnitOfMeasureGeneralResponse,
    prefix="/general",
    tags=["a76.general_catalogs.units_of_measure"],
    resource_name="UnitOfMeasureGeneral",
    id_name="id",
    enable_list=True,
    enable_filters=True,
    max_page_size=10000,
    # Permisos
    list_permissions=["cat_um_general.view"],
    get_permissions=["cat_um_general.view"],
    create_permissions=["cat_um_general.create"],
    update_permissions=["cat_um_general.edit"],
    delete_permissions=["cat_um_general.delete"],
).router
router.include_router(general_router)

# Main UnitOfMeasure
# Note: We use prefix="" to map to /units-of-measure/
main_router = TenantCRUDRoutes(
    service=service.UnitOfMeasureService,
    create_schema=dto.UnitOfMeasureCreate,
    update_schema=dto.UnitOfMeasureUpdate,
    response_schema=dto.UnitOfMeasureResponse,
    prefix="",
    tags=["a76.general_catalogs.units_of_measure"],
    resource_name="UnitOfMeasure",
    id_name="id",
    enable_list=True,
    enable_filters=True,
    max_page_size=10000,
    # Permisos
    list_permissions=["cat_um_general.view"],
    get_permissions=["cat_um_general.view"],
    create_permissions=["cat_um_general.create"],
    update_permissions=["cat_um_general.edit"],
    delete_permissions=["cat_um_general.delete"],
).router
router.include_router(main_router)
