# -*- coding: utf-8 -*-
"""
HIPPO API Routes
"""

from flask import Blueprint, jsonify, request
from .service import get_hippo_service

hippo_bp = Blueprint('hippo', __name__)


@hippo_bp.route('/chat', methods=['POST'])
def chat():
    """
    HIPPO chat endpoint
    ---
    tags:
        - HIPPO AI Assistant
    parameters:
        - in: body
          name: body
          schema:
            type: object
            required:
                - message
            properties:
                message:
                    type: string
                    description: User's message
                history:
                    type: array
                    description: Conversation history
    responses:
        200:
            description: HIPPO's response
    """
    data = request.get_json(silent=True) or {}
    message = data.get('message', '')
    history = data.get('history', [])

    if not message:
        return jsonify({'error': 'Message is required'}), 400

    hippo = get_hippo_service()
    response = hippo.chat(message, history)

    return jsonify(response)


@hippo_bp.route('/greeting', methods=['GET'])
def greeting():
    """
    Get HIPPO's greeting message
    ---
    tags:
        - HIPPO AI Assistant
    responses:
        200:
            description: Greeting message
    """
    hippo = get_hippo_service()
    return jsonify(hippo.get_greeting())


@hippo_bp.route('/health', methods=['GET'])
def health():
    """
    Check if HIPPO service is running
    """
    return jsonify({'status': 'ok', 'service': 'HIPPO'})
