<commit_before>module State exposing (init, update, subscriptions)

import Authentication
import Http
import Keycloak
import Navigation
import Ports
import Regulation.Rest exposing (getRegulations, postRegulation)
import Regulation.Types exposing (Regulation)
import Route
import Types exposing (..)


init : Maybe Keycloak.LoggedInUser -> Navigation.Location -> ( Model, Cmd Msg )
init initialUser location =
    let
        ( route, routeCmd ) =
            Route.init (Just location)
    in
        ( { count = 0
          , authModel = (Authentication.init Ports.keycloakShowLock Ports.keycloakLogout initialUser)
          , route = route
          , selectedTab = 0
          , regulations = []
          , newRegulation = Regulation 0 "" "" ""
          }
        , Cmd.batch [ routeCmd, getRegulations ]
        )


update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
    case msg of
        Types.AuthenticationMsg authMsg ->
            let
                ( authModel, cmd ) =
                    Authentication.update authMsg model.authModel
            in
                ( { model | authModel = authModel }, Cmd.map Types.AuthenticationMsg cmd )

        NavigateTo maybeLocation ->
            case maybeLocation of
                Nothing ->
                    model ! []

                Just location ->
                    model
                        ! [ Navigation.newUrl (Route.urlFor location)
                          , Ports.setTitle (Route.titleFor location)
                          ]

        UrlChange location ->
            let
                _ =
                    Debug.log "UrlChange: " location.hash
            in
                { model | route = Route.locFor (Just location) } ! []

        GetRegulations model ->
            let
                _ =
                    Debug.log "calling GetRegulations"
            in
                model ! [ postRegulation model ]

        SetRegulationURIInput value ->
            let
                oldRegulation =
                    model.newRegulation

                updatedRegulation =
                    { oldRegulation | uri = value }
            in
                ( { model | newRegulation = updatedRegulation }, Cmd.none )

        SetRegulationIDInput value ->
            let
                oldRegulation =<commit_msg>This demonstrates calling the applyMDC port from Elm.<commit_after>module State exposing (init, update, subscriptions)

import Authentication
import Http
import Keycloak
import Navigation
import Ports
import Regulation.Rest exposing (getRegulations, postRegulation)
import Regulation.Types exposing (Regulation)
import Route
import Types exposing (..)


init : Maybe Keycloak.LoggedInUser -> Navigation.Location -> ( Model, Cmd Msg )
init initialUser location =
    let
        ( route, routeCmd ) =
            Route.init (Just location)
    in
        ( { count = 0
          , authModel = (Authentication.init Ports.keycloakShowLock Ports.keycloakLogout initialUser)
          , route = route
          , selectedTab = 0
          , regulations = []
          , newRegulation = Regulation 0 "" "" ""
          }
        , Cmd.batch [ routeCmd, getRegulations, Ports.applyMDC () ]
        )


update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
    case msg of
        Types.AuthenticationMsg authMsg ->
            let
                ( authModel, cmd ) =
                    Authentication.update authMsg model.authModel
            in
                ( { model | authModel = authModel }, Cmd.map Types.AuthenticationMsg cmd )

        NavigateTo maybeLocation ->
            case maybeLocation of
                Nothing ->
                    model ! []

                Just location ->
                    model
                        ! [ Navigation.newUrl (Route.urlFor location)
                          , Ports.setTitle (Route.titleFor location)
                          , Ports.applyMDC ()
                          ]

        UrlChange location ->
            let
                _ =
                    Debug.log "UrlChange: " location.hash
            in
                { model | route = Route.locFor (Just location) } ! []

        GetRegulations model ->
            let
                _ =
                    Debug.log "calling GetRegulations"
            in
                model ! [ postRegulation model ]

        SetRegulationURIInput value ->
            let
                oldRegulation =
                    model.newRegulation

                updatedRegulation =
                    { oldRegulation | uri = value }
            in
                ( { model | newRegulation = updatedRegulation }, Cmd.none )

        SetRegulationIDInput value ->
            let
                oldRegulation =
{'fraction_non_alphanumeric': 0.07069435703796938, 'fraction_numerical': 0.0012586532410320957, 'mean_word_length': 1.3887775551102204, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '616287', 'n_tokens_mistral': 1199, 'n_tokens_neox': 1101, 'n_words': 305}