from flask import Flask
from flask_restful import Api, Resource, reqparse
from flask_swagger_ui import get_swaggerui_blueprint
import os

app = Flask(__name__)
api = Api(app)

# Sample data
people = [
    {
        "id": 1,
        "name": "John Doe",
        "age": 30,
        "pets": [
            {"id": 1, "name": "Fluffy", "type": "cat"},
            {"id": 2, "name": "Buddy", "type": "dog"}
        ]
    },
    {
        "id": 2,
        "name": "Jane Doe",
        "age": 28,
        "pets": [
            {"id": 3, "name": "Max", "type": "dog"}
        ]
    }
]

class PeopleListResource(Resource):
    def get(self):
        return people, 200

class PersonResource(Resource):
    def get(self, person_id):
        person = next((p for p in people if p["id"] == person_id), None)
        if person:
            return person, 200
        return {"error": "Person not found"}, 404


class AdminResource(Resource):
    def put(self):
        return {"username": "weakAdmin", "password": "weakAdmin"}, 200

api.add_resource(PeopleListResource, '/people')
api.add_resource(PersonResource, '/people/<int:person_id>')
api.add_resource(AdminResource, '/admin')

# Swagger UI setup
SWAGGER_URL = '/swagger'
API_URL = '/static/swagger.json'
swaggerui_blueprint = get_swaggerui_blueprint(
    SWAGGER_URL,
    API_URL,
    config={
        'app_name': "People and Pets API"
    }
)
app.register_blueprint(swaggerui_blueprint, url_prefix=SWAGGER_URL)

if __name__ == '__main__':
    os.environ["WERKZEUG_DEBUG_PIN"]='111-111-111'
    app.run(host='0.0.0.0', port=8335, debug=True)
