from flask import Blueprint, make_response, redirect, render_template, request, session, url_for

from src.lib.dms import approve_dms, cleanup_unapproved_dms, get_unapproved_dms
from src.types.props import SuccessProps

from .types import DMPageProps, ImportProps, StatusPageProps

importer_page_bp = Blueprint("importer_page", __name__)


@importer_page_bp.get("/importer")
def importer():
    props = ImportProps()

    response = make_response(render_template("importer_list.html", props=props), 200)
    response.headers["Cache-Control"] = "max-age=60, public, stale-while-revalidate=2592000"
    return response


@importer_page_bp.get("/importer/tutorial")
def importer_tutorial():
    props = ImportProps()

    response = make_response(render_template("importer_tutorial.html", props=props), 200)
    response.headers["Cache-Control"] = "max-age=60, public, stale-while-revalidate=2592000"
    return response


@importer_page_bp.get("/importer/tutorial_fanbox")
def importer_tutorial_fanbox():
    props = ImportProps()

    response = make_response(render_template("importer_tutorial_fanbox.html", props=props), 200)
    response.headers["Cache-Control"] = "max-age=60, public, stale-while-revalidate=2592000"
    return response


@importer_page_bp.get("/importer/ok")
def importer_ok():
    props = ImportProps()

    response = make_response(render_template("importer_ok.html", props=props), 200)
    response.headers["Cache-Control"] = "max-age=60, public, stale-while-revalidate=2592000"
    return response


@importer_page_bp.get("/importer/status/<import_id>")
def importer_status(import_id):
    is_dms = bool(request.args.get("dms"))

    props = StatusPageProps(import_id=import_id, is_dms=is_dms)
    response = make_response(render_template("importer_status.html", props=props), 200)

    response.headers["Cache-Control"] = "max-age=0, private, must-revalidate"
    return response
