"""General API routes not tied to a specific domain resource."""
from flask import Blueprint, jsonify, request

misc_bp = Blueprint('misc_api', __name__)


@misc_bp.route('/hello', methods=['GET'])
def hello():
    """A simple hello world endpoint.
    ---
    tags:
        - Sample endpoints
    responses:
        200:
            description: A greeting message
            content:
                application/json:
                    schema:
                        $ref: '#/components/schemas/HelloResponse'
                    example:
                        message: Hello from Flask API!
                        status: success
    """
    return jsonify({
        'message': 'Hello from Flask API!',
        'status': 'success'
    })


@misc_bp.route('/data', methods=['GET'])
def get_data():
    """Example endpoint that returns some data.
    ---
    tags:
        - Sample endpoints
    responses:
        200:
            description: A list of items
            content:
                application/json:
                    schema:
                        $ref: '#/components/schemas/DataItemsResponse'
                    example:
                        items:
                            - id: 1
                              name: Item 1
                            - id: 2
                              name: Item 2
    """
    return jsonify({
        'items': [
            {'id': 1, 'name': 'Item 1'},
            {'id': 2, 'name': 'Item 2'},
            {'id': 3, 'name': 'Item 3'}
        ]
    })


@misc_bp.route('/echo', methods=['POST'])
def echo():
    """Example endpoint that echoes back posted data.
    ---
    tags:
        - Sample endpoints
    requestBody:
        required: true
        content:
            application/json:
                schema:
                    $ref: '#/components/schemas/EchoRequest'
    responses:
        200:
            description: Echo response
            content:
                application/json:
                    schema:
                        $ref: '#/components/schemas/EchoResponse'
    """
    data = request.get_json()
    return jsonify({
        'received': data,
        'status': 'received'
    })
