from api_validations.validations_request import (
    InsertBuildDecisionBookProjectItems,
    UpdateBuildDecisionBookProjects,
    ApprovalsBuildDecisionBookProjects,
)


def generate_update_project_item(**kwargs):
    return {
        "build_decision_book_project_uu_id": kwargs.get(
            "build_decision_book_project_uu_id", None
        ),
        "is_out_sourced": kwargs.get("is_out_sourced", False),
        "project_note": kwargs.get("project_note", None),
        # "decision_book_pdf_path": str(kwargs.get("decision_book_pdf_path", None)),
        "status_id": kwargs.get("status_id", None),
        "resp_company_fix_wage": kwargs.get("resp_company_fix_wage", None),
        "contact_agreement_path": kwargs.get("contact_agreement_path", None),
        "contact_agreement_date": kwargs.get("contact_agreement_date", None),
        "contact_uu_id": kwargs.get("contact_uu_id", None),
        "resp_company_uu_id": kwargs.get("resp_company_uu_id", None),
        "approved_price": kwargs.get("approved_price", None),
    }


def generate_approval_project_item(**kwargs):
    return {
        "build_decision_book_project_uu_id": kwargs.get(
            "build_decision_book_project_uu_id", None
        ),
        "final_price_list": kwargs.get("final_price_list", None),
        "project_stop_date": kwargs.get("project_stop_date", None),
        "status_code": kwargs.get("status_code", None),
    }


def generate_insert_project_item(**kwargs):
    return {
        "build_decision_book_project_uu_id": kwargs.get(
            "build_decision_book_project_uu_id", None
        ),
        "item_header": kwargs.get("item_header", ""),
        "item_comment": kwargs.get("item_comment", ""),
    }


def create_decision_book_project_items(requester, insert_project_item):
    response = requester.post(
        endpoint="/build/decision_book/project/items/create", data=insert_project_item
    )
    print("text", response.text)
    print("json", response.json())
    return response.json()


def update_decision_book_project(requester, update_project_item):
    response = requester.post(
        endpoint="/build/decision_book/project/update", data=update_project_item
    )
    print("text", response.text)
    print("json", response.json())


def approve_build_decision_book_project_approval(requester, approval_project_item):
    response = requester.post(
        endpoint="/build/decision_book/project/approval", data=approval_project_item
    )
    print("text", response.text)
    print("json", response.json())


def list_decision_book_project(requester, project_no):
    response = requester.post(
        endpoint="/build/decision_book/project/list",
        data={"query": {"project_no": project_no}},
    )
    print("text", response.text)
    print("json", response.json())
    response_json = response.json()
    # project = response_json["data"][0]["uu_id"]
    project = response_json["data"][0]
    return project
