"""
Files router module.

This module provides API endpoints for file management operations including
upload, download, listing, and deletion of files.
"""

from typing import List, Dict, Any, Optional
from fastapi import (
    APIRouter,
    Depends,
    Query,
    UploadFile,
    File,
    Form,
    HTTPException,
    status,
)
from sqlalchemy.orm import Session
from starlette.responses import Response

from src.core.database import get_db
from src.apps.auth.utils.auth import get_current_active_user
from src.apps.users.models.user import User
from src.apps.files import file_services
from src.core.utils.enums import FileTypes
from src.apps.subscriptions.subscriptions_constants import (
    DEFAULT_SUBSCRIPTION_LIST,
    DEFAULT_SUBSCRIPTION_DETAILS,
    DEFAULT_SUBSCRIPTION_ACTIVITY_LIST,
)

router = APIRouter()


@router.get("")
async def list_subscriptions() -> Dict[str, Any]:
    """
    List all available subscriptions.
    """
    try:
        response = DEFAULT_SUBSCRIPTION_LIST
        return {
            "data": response,
            "meta": {
                "total": 4,
                "page": 1,
                "per_page": 10,
                "total_pages": 1,
                "has_next": False,
                "has_previous": False,
            },
            "links": {
                "next": None,
                "previous": None,
                "first": "/api/v1/customers?page=1&per_page=10",
                "last": "/api/v1/customers?page=1&per_page=10",
            },
            "success": True,
        }
    except Exception as e:
        raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail=str(e))


@router.get("/{id}", response_model=Dict[str, Any])
async def get_subscription(
    id: str,
    # current_merchant: MerchantSchema = Depends(get_current_merchant),
    # current_user: UserSchema = Depends(get_current_user)
):
    """
    Get a subscription by id.
    """
    try:
        response = {
            "data": DEFAULT_SUBSCRIPTION_DETAILS,
            "success": True,
            "message": "Subscription details fetched successfully.",
        }
        return response
    except Exception as e:
        raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail=str(e))


@router.get("/{id}/activities", response_model=Dict[str, Any])
async def get_subscription(
    id: str,
    # current_merchant: MerchantSchema = Depends(get_current_merchant),
    # current_user: UserSchema = Depends(get_current_user)
):
    """
    Get a subscription by id.
    ```
    {
        "data": [
            {
                "level": "info",
                "event": "EVENTS.AUTHORIZATION.CREATE",
                "message": "MFX Corp. has authorized a CHECKBOX authorization on behalf of Theriton Corp.  ",
                "module": "authorization",
                "submodule": "authorization",
                "data": null,
                "created_by": "Mason  Fox",
                "created_by_id": "54",
                "merchant_id": null,
                "customer_id": null,
                "contact_id": null,
                "receipt_id": null,
                "invoice_id": null,
                "payment_request_id": null,
                "product_slug": null,
                "authorization_type": "default",
                "authorization_id": "auth_7cZYJ3uL6aWoeKQ",
                "ip_address": "223.185.30.151",
                "phone": null,
                "contract_id": null,
                "checkout_id": null,
                "created_at": "2024-10-07T07:26:13.741000"
            }
        ],
        "message": "Activities fetched successfully",
        "success": true
    }
    ```
    """
    try:
        response = {
            "data": DEFAULT_SUBSCRIPTION_ACTIVITY_LIST,
            "message": "Activities fetched successfully",
            "success": True,
        }
        return response
    except Exception as e:
        raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail=str(e))
