*** Settings ***
Documentation     Integration tests for v3 database lifecycle models: LifecycleActionModel
...               and LifecyclePlanModel round-trip persistence with SQLite.
...               Covers commit 548a09f stages A5.3, A5.4, and plan hierarchy support.
Resource          ${CURDIR}/common.resource
Suite Setup       Setup Test Environment
Suite Teardown    Cleanup Test Environment

*** Variables ***
${HELPER_SCRIPT}    robot/helper_db_lifecycle_models.py

*** Test Cases ***
Action Domain Model Round Trip Through SQLAlchemy
    [Documentation]    Verify Action -> LifecycleActionModel -> Action preserves all fields
    [Tags]    database    action    roundtrip
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    action-round-trip    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    action-round-trip-ok

Plan Domain Model Round Trip Through SQLAlchemy
    [Documentation]    Verify Plan -> LifecyclePlanModel -> Plan preserves all fields including FK
    [Tags]    database    plan    roundtrip
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    plan-round-trip    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    plan-round-trip-ok

Plan Parent Child Hierarchy Persistence
    [Documentation]    Verify parent_plan_id and root_plan_id FK relationships persist correctly
    [Tags]    database    plan    hierarchy
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    plan-hierarchy    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    plan-hierarchy-ok

Action State Query By Index
    [Documentation]    Verify actions can be queried by state and namespace using indexes
    [Tags]    database    action    query
    ${result}=    Run Process    ${PYTHON}    ${HELPER_SCRIPT}    action-state-query    cwd=${WORKSPACE}
    Should Be Equal As Integers    ${result.rc}    0
    Should Contain    ${result.stdout}    action-state-query-ok
