<?php
    include "../../utils/Database.php";
    include "../../utils/functions.php";
    include "../../models/Config.php";
    include "../../services/ConfigService.php";
?>

<?php

    $database = new Database();
    $db = $database->connect();

    $config_service = new ConfigService($db);

    if (isset($_POST['update'])) {

        $config = new Config(
            $_POST['phone_number'],
            $_POST['mobile_number'],
            $_POST['address'],
            $_POST['email'],
            $_POST['facebook'],
            $_POST['instagram'],
            $_POST['twitter'],
            $_POST['linkedin']
        );

        $result = $config_service->update($config);

        if($result){
            set_notification("Successfully updated","success");
        } else {
            set_notification("Some error occurred");
        }
    }

    $result = $config_service->get();

    $config = new Config(
        $result['phone_number'],
        $result['mobile_number'],
        $result['address'],
        $result['email'],
        $result['facebook'],
        $result['instagram'],
        $result['twitter'],
        $result['linkedin']
    );
?>