-- Staging model: GIAS school links (predecessor/successor chains)

with source as (
    select * from {{ source('raw', 'gias_links') }}
),

renamed as (
    select
        cast("URN" as integer)              as urn,
        cast("LinkURN" as integer)          as linked_urn,
        "LinkType"                          as link_type,
        case when "LinkEstablishedDate" = '' then null else to_date("LinkEstablishedDate", 'DD-MM-YYYY') end as link_date
    from source
    where "URN" is not null
      and "LinkURN" is not null
)

select * from renamed
