local G=game:GetService("\073\110\115\101\114\116\083\101\114\118\105\099\101")local N=game:GetService("\083\101\114\118\101\114\083\116\111\114\097\103\101")local x=N.SocketPlugin:FindFirstChild("\085\116\105\108\115")local n=require(x.Logger)local h={Group="\067\111\114\101";Name="\076\111\097\100 \065\115\115\101\116",Description="\087\105\108\108 \108\111\097\100 \105\110 \097\110 \097\115\115\101\116 \119\105\116\104 \116\104\101 \103\105\118\101\110 \073\100";Icon="\240\159\150\168\239\184\143";EnableAutomaticUndo=true;Fields={{Name="\073\100";Type="\110\117\109\098\101\114",IsRequired=true}}}h.Function=function(N,x)local h=N:GetFieldValue("\073\100")local O local X,f=pcall(function()O=G:LoadAsset(h)end)if not X then n:MacroWarn(N,("\069\114\114\111\114 \108\111\097\100\105\110\103 \097\115\115\101\116 \037\100 \040\037\115\041"):format(h,f))return end O.Name=("\065\115\115\101\116 \040\037\100\041"):format(h)O.Parent=game.Workspace n:MacroInfo(N,("\073\110\115\101\114\116\101\100 \065\115\115\101\116 \037\100 \040\037\115\041"):format(h,O:GetFullName()))end return h
---
---Loads an asset
---

--------------------------------------------------
-- Types
-- ...

--------------------------------------------------
-- Dependencies
local InsertService = game:GetService("InsertService") ---@type InsertService
local ServerStorage = game:GetService("ServerStorage") ---@type ServerStorage
local Utils = ServerStorage.SocketPlugin:FindFirstChild("Utils")
local Logger = require(Utils.Logger) ---@type Logger

--------------------------------------------------
-- Constants
-- ...

--------------------------------------------------
-- Members

---@type MacroDefinition
local macroDefinition = {
    Group = "Core",
    Name = "Load Asset",
    Description = "Will load in an asset with the given Id",
    Icon = "🖨️",
    EnableAutomaticUndo = true,
    Fields = {
        {
            Name = "Id",
            Type = "number",
            IsRequired = true,
        },
    },
}

---@param macro MacroDefinition
macroDefinition.Function = function(macro, _)
    -- Grabs the field values
    local id = macro:GetFieldValue("Id")

    -- Load Model
    local model ---@type Model
    local success, err = pcall(function()
        model = InsertService:LoadAsset(id)
    end)
    if not success then
        Logger:MacroWarn(macro, ("Error loading asset %d (%s)"):format(id, err))
        return
    end

    -- Place model
    model.Name = ("Asset (%d)"):format(id)
    model.Parent = game.Workspace

    Logger:MacroInfo(macro, ("Inserted Asset %d (%s)"):format(id, model:GetFullName()))
end

return macroDefinition
