from flask import Blueprint, request, jsonify
from flask_login import login_required
from app.services.systems_service import SystemService

system_bp = Blueprint('system', __name__,url_prefix='/systems')
system = SystemService()

@system_bp.route('/', methods=['GET'], strict_slashes=False)
@login_required
def list_systems():
    return jsonify(system.get_systems(
        page=request.args.get('page', 1, type=int),
        per_page=request.args.get('per_page', 10, type=int),
        sort_field=request.args.get('sort_field', 'system_id'),
        sort_order=request.args.get('sort_order', 'asc')
    ))

@system_bp.route('/', methods=['POST'],strict_slashes=False)
@login_required
def add_system():
    return system.add_system(request.json)

@system_bp.route('/', methods=['PUT'],strict_slashes=False)
@login_required
def update_system():
    return system.update_system_name(request.json)

@system_bp.route('/<int:system_id>', methods=['DELETE'],strict_slashes=False)
@login_required
def delete_system(system_id):
    return system.delete_system(system_id)
