-- IMPORTS
WITH documents AS (
    SELECT * FROM {{ source('src_exchange_mysql', 'documents') }}
),


-- LOGIC
documents_rename AS (

    SELECT
        documents.id,
        documents.owner_type,
        documents.owner_id,
        documents.document_type,
        documents.reference,
        documents.status,
        documents.issued_date                                                                        AS issued_at,
        documents.expired_date                                                                       AS expired_at,
        documents.approver                                                                           AS approved_by,
        documents.approval_date                                                                      AS approved_at,
        documents.deleted_at,
        documents.created_at,
        documents.updated_at,
        current_timestamp()                                                                          AS _dbt_ran_at

    FROM documents
),


-- FINAL
final__base_exchange__documents AS (

    SELECT
        id,
        owner_type,
        owner_id,
        document_type,
        reference,
        status,
        issued_at,
        expired_at,
        approved_by,
        approved_at,
        deleted_at,
        created_at,
        updated_at,
        _dbt_ran_at

    FROM documents_rename

) 

SELECT * FROM final__base_exchange__documents